Backend for mobile app dev project(wachet)
yarn && yarn serve
Listen port 3000
- Request
Url:/login
Method:POST
Body:where### x-www-form-urlencoded formated ### { "name": string, "pwd": string }
pwd
has been hashed - Response
HTTP code:200 OK | 404 Not Found
Body:browser will be set cookie here{ "id": number, "token": string, "expireTime": timestamp }
note:token
used to build websocket connection
- Request
Url:/logout
Method:POST
Body: no body - Response
HTTP code:204 No Content | 403 Forbidden
Body: no body
- Request
Url:/friends
Method:GET
Body: no body - Response
HTTP code:200 OK | 403 Forbidden
Body:[ { "id": number, "name": string, "avatar": string } ]
- Request
Url:/channels
Method:GET
Body: no body - Response
HTTP code:200 OK | 403 Forbidden
Body:[ { "name": string, "users": [ { "id": number, "name": string, "avatar": string } ] } ]
After login, client creates a websocket connection with server
Listen port 3001
- Client
all actions should be uncapitalized
{ "action": "hello", "msg": { "token": string } }
note:token
gotten fromlogin
API - Server
this response means server authorized user
{ "action": "hi", "msg": { "id": number, "name": string, "avatar": string } }
- Client
{ "action": "new-chat", "msg": { "to": [ { "id": number } ] } }
id
is a user id - Server
to Client:returns created channel{ "action": "new-chat-res", "msg": { "channel": string } }
- Server
{ "action": "pull-message", "msg": { "messages": [ IMessageType ] } }
IMessageType
is defined as:{ "uuids": [ { "user": number, "uuid": number } ], "sender": { "id": number, "name": string, "avatar": string }, // user "msgId": number, "channel": string, "content": string, "time": timestamp }
- Client
{ "action": "client-received", "msg": { "uuids": [number] } }
sequence
is to distinguish which message client received
- Client
{ "action": "push-message", "msg": { "sequence": number, "channel": string, "content": string } }
- Server
where
{ "action": "server-received", "msg": { "sequence": number, "time": timestamp, "msgId": number } }
sequence
is to distinguish wich message has been received
forbidden
: No access to current channelinvalid-param
: Param invalidtoken-missing
: Token given missing or incorrect