This server is used as a companion for the client challenge.
The server will sometime be a bit capricious, you might observe:
- failure to receive a response
- timeouts when trying to send a message
- duplicate events being received in the messages stream
When that happens, you should retry and react accordingly.
Note: persistence is in-memory only, and restarting the server will reset its state.
- You need to install Go on your system: follow the official documentation
- Then, execute the command:
go run .
You might want to allow the server to be reached from another machine (a simulator or a phone for example). One way to do that is to use ngrok.
- You need to install Ngrok on your system: follow the official documentation
- Then, after having started the go server (see above), execute the command
ngrok http 3000.
This will give you a public URL of the form
https://9f98-62-194-145-77.ngrok.io, that can be used to reach your server
from any system that has an internet connection.
This API exposes a few HTTP endpoints and an SSE stream. It allows to list chats, and read & write messages.
- All the
POSTendpoints expect anIdempotency-Keyheader, it must be a string unique to each request (and their respective retries). For more details, see here. A valid header could be:Idempotency-Key: 459cfe7e-5952-43a0-a0ff-b2d8f1f4cfad.
GET /events?stream=messages: an SSE stream that sends youMessageentities as they are ingested by the serverGET /chats: returns a list of allChatentitiesGET /chats/{chat_id}/messages: returns a list of the 100 most recentMessageentities in a chatPOST /chats/{chat_id}/messages: send a new message in a chat and returns the newly createdMessageentity. It expects a JSON payload of the form:{ "text": "..." }
id(number): the chat idname(string): the chat name
id(number): the message idchat_id(number): the id of the chat this message belongs toauthor(string): the message author (either the constant string"user"or"bot")text(string): the actual content of the messagesent_at(string): the date at which the message was sentidempotency_key(string): the idempotency key that was passed during the message creation