When user has authorized or registered he gets a token that he must provide in each request to server.
POST /api/login
Content-type: application/x-www-form-urlencoded
Body:
name: {name}
password: {password}
Status: 200
Content-type: application/json
Body: {"status": "ok"}
Location: /api/chats
Cookies:
user_id={id}
token={...}
Status: 400
Content-type: application/json
Body:
{"error": "{description of error}"}
It is required access_token and user_id in request cookies.
GET /api/logout
Status: 200
Content-type: application/json
Body: {"status": "ok"}
Location: /api/login
Cookies:
user_id={' '}
token={' '}
It is required access_token and user_id in request cookies.
-
GETget user`s chats -
POSTcreate chat
Content-type: application/x-www-form-urlencoded
Body: title: {title}
DELETEdelete user from chat
Params : chat_id={chat_id}
GET
Status: 200
Content-type: application/json
Body:
{
"chats": [
{
"id": {id},
"last_message": {last_message},
"last_message_time": {last_message},
"sender_id": {sender_id},
"title": {title}
},
...
]
}
POST
Status: 201
Content-type: application/json
Body: {"status": "ok"}
DELETE
Status: 200
Content-type: application/json
Body: {"status": "ok"}
Status: 400/404/403
Content-type: application/json
Body:
{"error": "{description of error}"}
It is required access_token and user_id in request cookies.
-
GETget chat`s messages -
POSTsend message in chat (only authorized user with access to chat)
Content-type: application/x-www-form-urlencoded
Body: content: {content}
PUTchange chat title (only authorized user with access to chat)
Content-type: application/x-www-form-urlencoded
Body: title: {title}
DELETEdelete users messege (only authorized users messages)
Params : id={mes_id}
GET
Status: 200
Content-type: application/json
Body:
{
"messages": [
{
"content": {content},
"id": {id},
"sender_id": {sender_id},
"time": {time}
},
...
]
}
POST
Status: 201
Content-type: application/json
Body: {"status": "ok"}
PUT
Status: 200
Content-type: application/json
Body: {"status": "ok"}
DELETE
Status: 200
Content-type: application/json
Body: {"status": "ok"}
Status: 400/404/403
Content-type: application/json
Body:
{"error": "{description of error}"}
It is required access_token and user_id in request cookies.
GETget user information
Params : name={name}
POSTcreate user and auth
Content-type: application/x-www-form-urlencoded
Body:
name: {name}
password: {password}
email: {email}
PUTchange user information (only authorized)
Content-type: application/x-www-form-urlencoded
Body:
name: {name}
email: {email}
DELETEdelete user (only authorized)
GET
Status: 200
Content-type: application/json
Body:
{
"user":
{
"name": {name},
"email": {email}
}
}
POST
Status: 201
Content-type: application/json
Body: {"status": "ok"}
Location: /api/chats
Cookies:
user_id={id}
token={...}
PUT
Status: 200
Content-type: application/json
Body: {"status": "ok"}
DELETE
Status: 200
Content-type: application/json
Body: {"status": "ok"}
Status: 400/404/403
Content-type: application/json
Body:
{"error": "{description of error}"}