This is a submission of the backend assignment of 2023 TikTok Tech Immersion, based upon the demo template.
The HTTP server serves as an interface for users, in which it connects with a micoservice RPC server which uses Redis database to store the messages.
Run the following command the same directory as
docker-compose.yml
to initialise the necessary Docker
containers:
docker compose up -d
To send a message, we send a POST
request to
localhost:8080/api/send
, specifying the following URL
parameters:
chat
: Name of chat in the form[USER A]:[USER B]
sender
: Name of sendertext
: Text in message
Example To send "hi" from a to b, we use the following command:
curl -X POST 'localhost:8080/api/send?chat=a:b&sender=a&text=hi'
To send a message, we send a GET
request to
localhost:8080/api/pull
, specifying the following URL
parameters:
chat
: Name of chat in the form[USER A]:[USER B]
cursor
: Earliest epoch time of messages to retrieve, 0 by defaultlimit
: Maximum number of messages to retrieve, 10 by defaultreverse
: Boolean value of whether to sort messages in ascending order by time
Example
To retrieve all messages between a and b (i.e., chat a:b
),
we use the following command:
curl 'localhost:8080/api/pull?chat=a:b&cursor=0&limit=10&reverse=false'
- Although we specified
cursor
as 0 andlimit
as 10, here, we could omit them. The request will default tocursor=0
andlimit=10
respectively.