It uses lowdb.js as a storage engine for educational purposes.
- Express.js
- Jest
- Supertest
- DB https://github.com/typicode/lowdb
-
Install all dependencies.
npm install
-
Run server.
npm run start
-
Run tests.
npm run test
-
Run ES linter.
npm run lint
All requests except GET should be sent with header:
Content-Type: application/json
GET | POST | PUT | DELETE | |
---|---|---|---|---|
/auth | check auth | login | renew token? | logout |
/user | / get own profile /:id get user by ID /?nickname= search by nickname |
create account | update password | delete profile |
/chat | /:id get specific chat /?userId= find chats by owner ID /?participantId= find chats by participant /?title= find by title |
create chat | update / join | delete chat or exit |
/message | /?chatId= get messages of specific chat | create message | edit message | delete message |
Authenticate user. Send:
{
"nickname": "test",
"password": "123"
}
Receive:
{
"token": "GhkhAgw5JdGo8yLdBlhzOHbUlPaYKr"
}
Cookie "token=TOKEN" will be set. It is httpOnly cookie. All routes except POST /auth should be used with cookie "token=TOKEN".
Check auth status. Returns 200 if all is OK.
Logout. Deleting cookie and token.
Entity:
{
"id": "a17413f820d48",
"createdAt": "2020-10-20T03:48:24.718Z",
"nickname": "test"
}
Create a new user. Send:
{
"nickname": "test",
"password": "test123"
}
Receive:
User
Receive currently logged user profile:
User
Get user by ID. Receive:
User
Receive:
[ User, User, ... ]
Update user password. Send:
{
"password": "new_password"
}
Receive:
User
Entity:
{
"id": "853d59e4a2b8e",
"createdAt": "2020-10-20T03:48:24.735Z",
"title": "Super chat",
"userId": "a17413f820d48",
"participants": [
"a17413f820d48"
],
"isPrivate": false,
"isDialogue": false
}
Create a new chat. Send:
{
"title": "Chat title"
}
Or:
{
"title": "Chat title",
"participants": ["userId1", "userId2"]
}
Receive:
Chat
Create a new dialogue with specific user. Send:
{
"isDialogue": true,
"participants": ["a17413f820d48"]
}
Receive:
Chat
Receive:
Chat
Search by chat title. Private chats and dialogues will not be found. Receive:
[ Chat, Chat, ... ]
Get chats owned by user. Receive:
[ Chat, Chat, ... ]
Get chats user involved in. Receive:
[ Chat, Chat, ... ]
- Owner
Edit chat properties. Send: Chat
- Other user
Join chat.
Delete a chat by ID if owner. Exit chat if participant.
Entity:
{
"id": "5204cc9d39cfc",
"createdAt": "2020-10-20T03:48:24.741Z",
"content": "Here I write my message",
"userId": "a17413f820d48",
"chatId": "853d59e4a2b8e",
"type": "text"
}
Create a new message. Send:
{
"content": "Here is my message",
"chatId": "aa5eaed04c03d",
"type": "text"
}
Receive: Message
Get all messages of given chat.
Receive: [ Message, Message, .. ]
Delete a message by ID.
Connect to ws://hostname/message/chatId
- Listen to 'message' event
- Will receive
Message
objects
- Emit 'send' event with
Message
data
Use https://github.com/ai/nanoid instead of self written function- User:
- Update user profile
- Delete user profile
- Add to friend list
- Chat:
Implement dialogue modeStart dialoguePrivate chats should not be found
- Message:
Upload message with image- Delete message
- Edit message
Get new messages via web socket