API for chat application for DogeCodes React course.
This is a simple API server that implements a logic required to correct work of DogeCodes React Chat application.
To run this server localy you need to have these requirements:
Use following commands to run this API-server localy:
git clone https://github.com/dogecodes/react-chat-api.git
cd react-chat-api
npm install
npm run start:dev # or `npm start` for productionNote: Don't forget to start mongod for connection to database.
Current version of API is v1, so you need to specify the version of API before every route. For example:
http://localhost:8000/v1/users/me
http://localhost:8000/v1/chats
Here's the map of API's HTTP routes:
- /— routes related to authentication.- /signupPOST — create new user with- usernameand- password.
- /loginPOST — log user in with- usernameand- password.
- /logoutGET — log out active user.
 
- /users— routes related to users.- /usersGET — retrieve data about all users.
- /users/meGET — retrieve my user's data.
- /users/mePOST — update my user's information (- username,- firstName,- lastNameand- city).
- /users/:idGET — retrieve information about user with specific- :id.
 
- /chats— routes related to chats.- /chatsGET — retrieve information about all chats.
- /chatsPOST — create new chat with specified- title.
- /chats/myGET — get list of all user's chats.
- /chats/:idGET — get chat's information with messages by specific chat's- :id.
- /chats/:idPOST — send new message to chat with specific- :id.
- /chast/:idDELETE — delete chat with specific- :id. Only creator of the chat can delete it.
- /chats/:id/joinGET — join chat with specific- :id.
- /chats/:id/leaveGET — leave chat with specific- :id.
 
If you're using Insomnia for debugging APIs, you can download a workspace backup:
This API also emmits and listens some socket.io events.
Sockets connection requires authentication with access-token. Here's an example of establishing sockets connection:
import SocketIOClient from 'socket.io-client';
socket = SocketIOClient('path/to/api', {
  query: {
    token: '...your access-token here...',
  },
});Here's the list of events:
- new-message— emmited when someone sends new message to specific chat.
- new-chat— emmited when someone creates new chat.
- deleted-chat— emmited when someone deletes a chat.
- connection— connection of socket.io client.
- mount-chat— mount a client to listen for messages in chat with specific- :chatId.
- unmount-chat— unmout a client from listening for messages in chat with specific- :chatId.
- send-message— send message with- contentto chat with
MIT © Denys Dovhan
