This chat app uses a RESTful Nodejs backend to create chat rooms where clients can communicate.
Authors:
NOTE! If you are looking for delivery instructions, see README.pdf
instead!
In docker:
/
routeYou need docker installed to run the server in a docker container.
docker build -t rest-chat-app .
docker run -p 5000:5000 rest-chat-app // -p maps a docker port to a local port on your machine
To stop the docker container you could use:
docker stop $(dokcer ps -a -q)
Server:
Development mode:
5000
(or port assigned by environment variable PORT
)NOTIFY=false
if you don't want push notifications enabledTo run the server in development mode:
cd server
npm i
npm run dev
Production mode:
5000
(or port assigned by environment variable PORT
)NOTIFY=false
if you don't want push notifications enabledTo run server in production mode:
cd server
npm i
npm run start
Client:
Development mode:
localhost
5000
5500
To run the client in development mode:
cd app
npm i
npm run dev
Now, open your browser at localhost:5500
to interact with the client.
Production mode:
/
route to get the client.localStorage
api to keep logged when the browser is refreshed.Bots:
Bots in the terminal:
localhost
(or port assigned by environment variable SERVER_HOST
)5000
(or port assigned by environment variable SERVER_PORT
)bot
room or create one if it doesn't exist yet.To run a bot from the terminal:
cd client
HOST=localhost PORT=5000 node bot.js
Bots from UI:
To create bot in UI:
NB: Make sure you are using the LTS version of node: v14.16.0
.
Here you will find a list of every endpoint the chat api exposes and how to use each one
POST - /api/users
Creates a new user and returns a userID
Header:
Content-Type : application/json
Body:
{
"username" : "%username%",
"password" : "%password%"
}
Response body:
{
"message" : "User created"
}
GET - /api/users
Returns a list of all users
Header:
Token : "%Auth Token%"
Response body:
{
"users" : [
{
"id" : "%userID%",
"username" : "%username%"
}
]
}
GET - /api/user/:userID
Returns a user
Header:
Token : "%Auth Token%"
Response body:
{
"user" : {
"username" : "%username%",
"id" : "%userID%",
"ownedRooms" : [ "%roomID%" ],
"rooms" : [ "%roomID%" ]
}
}
DELETE - /api/user/:userID
Deletes a user specified by the userID
Header:
Token : "%Auth Token%"
Response body:
{
"message" : "User deleted"
}
POST - /api/tokens
Authenticates user, establishes connection and returns a new tokenID
Header:
Content-Type : application/json
Body:
{
"username" : "%username%",
"password" : "%password%"
}
Response body:
{
"token" : "%tokenID",
"message" : "Logged in"
}
GET - /api/token/:tokenID
Returns token
Header:
Token : "%Auth Token%"
Response body:
{
"token" : {
"id": "%tokenID%",
"username": "%username%",
"expires": "%expiration date%"
}
}
PUT - /api/token/:tokenID
Extends token
Header:
Token : "%Auth Token%"
Response body:
{
"message" : "Session extended"
}
DELETE - /api/token/:tokenID
Deletes and invalidates token
Header:
Token : "%Auth Token%"
Response body:
{
"message" : "Logged out"
}
POST - /api/rooms
Creates a chat room
Header:
Token: %tokenID%
Body:
{
"name" : "%room name%"
}
Response body:
{
"message" : "Room created"
}
GET - /api/rooms
Gets all chat rooms
Header:
Token : "%Auth Token%"
Response body:
{
"rooms" : [
{
"id" : "%roomID%",
"name" : "%room name%",
"joined": true
}
]
}
GET - /api/room/:roomID
Get room
Header:
Token : "%Auth Token%"
Response Body:
{
"room": {
"id": "%roomID%",
"name": "%room name%",
"admin": "%userID%",
"users": [
"%userID%"
],
"messages": [
{
"sender": "%user name%",
"message": "%message%"
}
]
}
}
DELETE - /api/room/:roomID
Delete room
Header:
Token : %tokenID%
Response body:
{
"message" : "Room deleted"
}
POST - /api/room/:roomID/users
Add user to room
Header:
Token : %tokenID%
Body:
{
"user" : "%userID%",
}
Response body:
{
"message" : "Added user to room"
}
GET - /api/room/:roomID/users
Get all users in room
Header:
Token : "%Auth Token%"
Response body:
{
"users" : [
{
"id" : "%userID%",
"username" : "%username%"
}
]
}
GET - /api/room/:roomID/messages
Get all messages in room
Header:
Token : %tokenID%
Response body:
{
"messages" : [
{
"id" : "%messageID%",
"message" : "%message%",
"author" : "%userID%",
"time" : "%time sent%"
}
]
}
GET - /api/room/:roomID/:userID/messages
Get all messages by user in room
Header:
Token : %tokenID%
Response body:
{
"messages" : [
{
"id" : "%messageID%",
"message" : "%message%",
"author" : "%userID%",
"time" : "%time sent%"
}
]
}
POST - /api/room/:roomID/:userID/messages
Add message to room
Header:
Token : %tokenID%
Body:
{
"message" : "%message%"
}
Response body:
{
"message" : "Message sent"
}
GET - /api/push
Check if server has push notifications enabled
Response body:
{
"push" : "enabled/disabled"
}