-
Notifications
You must be signed in to change notification settings - Fork 2
Chat API documentation
This document describes available API calls and provides example of resources that make up Company API.
- Root URL and data formats
- Authentication
- Errors
- User resources
- Conversation resources
- Message resources
Every request starts with /api
(if started locally for example, it is localhost:4000/api
). All data is received and sent as JSON.
Every API call requires basic authentication. To get a token you must first register. After completing registration you can login to get authentication token.
POST /api/login/
Parameters:
- email: String and
- password: String
Returns:
- User object,
- Token and
- Expiration value.
Request Example:
{
"creds" : {
"email": "[email protected]",
"password": "/fXLpFJV8u9dWcd"
}
}
Response Example:
{
"data": {
"user": {
"subname": "Doe",
"password": "/fXLpFJV8u9dWcd",
"name": "John",
"job": "CEO",
"id": 1,
"email": "[email protected]"
},
"token": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJDb21wYW55QXBpIiwiZXhwIjoxNTIyNDA2MzY4LCJpYXQiOjE1MTk5ODcxNjgsImlzcyI6IkNvbXBhbnlBcGkiLCJqdGkiOiIyZmE3OTU3Ni1mMmIzLTQ0MWMtOGZkNy1lOTE3OGUwZjA4OTciLCJuYmYiOjE1MTk5ODcxNjcsInN1YiI6IlVzZXI6MSIsInR5cCI6ImFjY2VzcyJ9.X7cYX3_McHzwqCsQo-tTYsXUG14SMk0S1yNWzj3qJ6gf2EqFeGDlqTQI93k9_KdU9hZRkcrz5yePsU4SJFaGQQ",
"expire": 1522406368
}
}
DELETE /api/logout
Parameters:
- None
Returns:
- Notification about successful logout
Response Example:
{
"data": "Success logout"
}
Forming and sending bad request will result in appropriate HTTP response code. Usual response codes are:
- 401 - Unauthorized and
- 422 - Unprocessable Entity.
User object has next attributes:
- id: Integer,
- name: String,
- subname: String,
- email: String,
- job: String and
- password: String.
POST /api/users/
Parameters:
- name: String,
- subname: String,
- email: String,
- job: String and
- password: String.
Returns:
- User object
Request Example:
{
"user" : {
"name": "John",
"subname": "Doe",
"email": "[email protected]",
"job": "CEO"
}
}
Response Example:
{
"subname": "Doe",
"password": "QFB0zLvkkXLoZ98",
"name": "Jane",
"job": "CEO",
"id": 2,
"email": "[email protected]"
}
PUT /api/users/:id
Parameters:
- password: String
Returns:
- User new password
Request Example:
{
"password": "johndoe"
}
Response Example:
"johndoe"
GET /api/users
Parameters:
- None
Returns:
- List of User objects
Response Example:
[
{
"subname": "Doe",
"password": "QFB0zLvkkXLoZ98",
"name": "Jane",
"job": "CEO",
"id": 2,
"email": "[email protected]"
},
{
"subname": "Doe",
"password": "johndoe",
"name": "John",
"job": "CEO",
"id": 1,
"email": "[email protected]"
}
]
Conversation has next attributes:
- id: Integer - Identification of conversation,
- sender_id: Integer - Message sender id,
- recipient_id: Integer - Message recipient id and
- status: String - Conversation status
POST /api/conversations/
Parameters:
- recipient_id
Returns:
- Conversation object
Request Example:
{
"recipient": 2
}
Response Example:
{
"status": null,
"id": 1
}
GET /api/conversations/
Parameters:
- None
Returns:
- List of Conversation objects
Response Example:
[
{
"status": null,
"id": 1
}
]
Message has next attributes:
- content: String - Message content,
- date: Date - Date of creation,
- conversation_id: Integer - To which conversation this message belongs and
- sender_id: Integer - Id of message sender.
GET /api/messages
Parameters:
- conv_id
Returns:
- List of Message objects
Request Example:
/api/messages?conv=id