base URL: https://...com/api/v1
socket URL: <baseUrl>?auth_token=<token>
auth header: Authorization: Bearer <token>
Registers a new user.
// request parameters
{
"mail": "user@gmail.com",
"password": "<sha512-encrypted password.domain>",
"username": "user123 <format: [a-zA-Z0-9-_]+>"
}
// response (if succeeded, status = 201)
{
"token": "Asdf...XX23",
"user": "<userObject>"
}
Logs an user in.
// request parameters
{
"password": "<sha512-encrypted password.domain>",
"username": "user123 <or> user@gmail.com"
}
// response (if succeeded, status = 200)
{
"token": "Asdf...XX23",
"user": "<userObject>"
}
Logs an user out. - but no function in current authentication model!
// no request parameters needed
// empty response (if succeeded, status = 204)
Returns user object of the authenticated user.
// response (if succeeded, status = 200)
{
"mail": "user@gmail.com",
"username": "user123",
"id": "<userId>",
"last_seen": "online <or> 2017-10-20T19:47:27.870Z",
"contacts": [
"<userObject>",
"..."
]
}
Returns a list of users whose mail or username contains the queried string.
// response (if succeeded, status = 200)
{
"users": [
"<userObject>",
"..."
]
}
Returns all messages sent by and to you.
// response (if succeeded, status = 200)
{
"messages": [
{
"recipient": "<userObject>",
"sender": "<userObject>",
"message": "hello world!",
"timestamp": "2017-10-20T19:47:27.870Z",
"id": "<messageId>"
},
{
"..."
}
]
}
Returns messages sent between you and the specified user.
// response (if succeeded, status = 200)
{
"messages": [
{
"recipient": "<userObject>",
"sender": "<userObject>",
"message": "hello world!",
"timestamp": "2017-10-20 19:47:27.870Z",
"id": "<messageId>"
},
{
"..."
}
]
}
Sends a message to another user.
// request parameters
{
"recipient": "<userId>",
"message": "hello world!"
}
// response (if succeeded, status = 201)
{
"message": "<messageObject>"
}
Returns the conversation between you and the specified user. If no such conversation exists (e.g. among cs students), returns null.
// response (if succeeded, status = 200)
{
"messages": [
"<messageObject>",
"..."
],
"participants": [
"<userObject>",
"..."
],
"last_message": "<messageObject>",
"id": "<conversationId>"
}
Returns all conversations featuring you.
// response (if succeeded, status = 200)
{
"conversations": [
"<conversationObject>",
"..."
]
}
Returns a list of all contacts.
// response (if succeeded, status = 200)
{
"contacts": [
"<userObject>",
"..."
]
}
Adds a contact.
// request parameters
{
"user": "<userId>"
}
// response (if succeeded, status = 201)
{
"contacts": [
"<userObject>",
"..."
]
}
Removes a contact.
// request parameters
{
"user": "<userId>"
}
// response (if succeeded, status = 200)
{
"contacts": [
"<userObject>",
"..."
]
}
Using socket.io as socket service.
Example for js socket.io library:
let socket = io.connect("<baseUrl>", {
query: "auth_token=" + "<token>"
})
Fired if authentication went right and everything is just waiting for
your awesome messages.
Example for js socket.io library:
socket.on("connect", () => {
// connected
})
Fired if client disconnected from server. Mostly caused by a network timeout or
if the server is down.
Example for js socket.io library:
socket.on("disconnect", (reason) => {
// console.log(reason)
})
Well, go and fix it. Mostly caused by authentication problems (e.g. token expired).
Example for js socket.io library:
socket.on("error", (error) => {
// console.log(error)
})
Listens to new messages which will be sent as a socket event to the recipient
and the sender.
Example for js socket.io library:
socket.on("message", (message) => {
// message is a <messageObject>
})
Listens to user events (e.g. updated last_seen) which will be sent as a socket
event to all connected sockets.
Example for js socket.io library:
socket.on("user", (user) => {
// user is a <userObject>
})