Backend REST API for:
- User login/registration system
- Private chat system between two users
- Tweet post create/retreive/update/delete system
Logs in user (requires username
and password
in request body):
POST /login
Registers user (requires username
and password
in request body):
POST /register
Retrieves private chat associated with another user:
GET /chat/{receiver_username}
Send private chat to another user (requires message
in request body):
POST /chat/{receiver_username}
Retreives a tweet post:
GET /tweet/{tweet_id}
Creates a new tweet post (requires message
in request body):
POST /tweet
Updates an existing tweet (requires message
in request body):
PATCH /tweet/{tweet_id}
Deletes an existing tweet:
DELETE /tweet/{tweet_id}
This project depends on external MySQL server running. After configuring .env
file at the root of this project hierarchy and creating a new user in MySQL server, run the following queries in MySQL console to create necessary data:
CREATE DATABASE Speer_API;
Use Speer;
CREATE TABLE Users (
id INT AUTO_INCREMENT,
username VARCHAR(100),
password VARCHAR(255),
PRIMARY KEY (id)
);
CREATE TABLE Chats (
id INT AUTO_INCREMENT,
sender_id INT,
receiver_id INT,
message VARCHAR(4096),
PRIMARY KEY (id),
FOREIGN KEY (sender_id) REFERENCES Users(id),
FOREIGN KEY (receiver_id) REFERENCES Users(id)
);
CREATE TABLE Tweets (
id INT AUTO_INCREMENT,
user_id INT,
tweet VARCHAR(4096),
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES Users(id)
);
Test assumes the DB already has following 3 users (username:password):
- admin:admin
- eric:eric
- sarah:sarah
Test assumes the DB already has a tweet (with id 5) in Tweets table.
Make sure to add these entries to the correct tables prior to unit testing!
Unit testing is available with Mocha framework. Simply run following line on console:
npm test