RESTful Chat API
Currently there is a single endpoint, /messages
, that can be used to create a message (with a POST
request) as well as to obtain a list of messages between users (with a GET
request). The endpoint returns JSON.
Create a POST
request to /messages
with the following parameters:
{
"sender": "sender_username",
"receiver": "receiver_username",
"text": "a text message"
}
The response looks like:
{
"message": {
"id": "message id",
"sender": "sender_username",
"receiver": "receiver_username",
"text": "the text of the message",
"created": "time in UTC",
"updated": "time in UTC"
}
}
Create a GET
request to /messages?user1=username1&user2=username2
to view the conversation between two users. Note that the order does not matter!
The response looks like:
{
"messages": [
{
"id": "an id",
"sender": "username1",
"receiver": "username2",
"text": "hi username2!",
"created": "time in UTC",
"updated": "time in UTC"
},
{
"id": "another id",
"sender": "username2",
"receiver": "username1",
"text": "hi username1!!",
"created": "time in UTC",
"updated": "time in UTC"
}
]
}
A json object with:
id
stringsender
username stringreceiver
username stringtext
the text of the message (string)created
time in UTCupdated
time in UTC
For example,
{
"id": "an id",
"sender": "bar",
"receiver": "foo",
"text": "hi foo!!",
"created": "time in UTC",
"updated": "time in UTC"
}
GET /messages?user1=foo&user2=bar
retrieves a list of messages between foo
and bar
. Note that this includes messages sent by foo
to bar
as well as messages sent by bar
to foo
and that the order does not matter.
user1
a string usernameuser2
a string username
The json response has a top level attribute messages
that is an array of message
objects.
{
"messages": [
{
"id": "an id",
"sender": "foo",
"receiver": "bar",
"text": "hi bar!",
"created": "time in UTC",
"updated": "time in UTC"
},
{
"id": "another id",
"sender": "bar",
"receiver": "foo",
"text": "hi foo!!",
"created": "time in UTC",
"updated": "time in UTC"
}
]
}
POST /messages?sender=foo&receiver=bar&text=something
creates a message from foo
to bar
with the text something
.
sender
a string usernamereceiver
a string usernametext
the text of the message (string)
The json response has a top level attribute message
that is a message
object.
{
"message": {
"id": "an id",
"sender": "foo",
"receiver": "bar",
"text": "something",
"created": "time in UTC",
"updated": "time in UTC"
}
}