Chat API
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.
Requirements
To run this server localy you need to have these requirements:
Installations
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.
API
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
HTTP
Here's the map of API's HTTP routes:
/โ routes related to authentication./signupPOST โ create new user withusernameandpassword./loginPOST โ log user in withusernameandpassword./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,lastNameandcity)./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 specifiedtitle./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:
Sockets
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:
Emmiting
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.
Listening
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 withcontentto chat with
License
MIT ยฉ Denys Dovhan
