This is a NodeJS project that simulates a social media REST API. It serves CRUD user endpoints as well as the relationship degree from one user to another.
To simplify and substitue a database, the project uses json file static/users.json
filled with some random user data.
It follows the schema:
{
"id": 1, // in a real world application this would be a primary key and should be some random identifier or a social number
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@doe.com",
"gender": "Female", // from enum { Female, Male, Non-binary, Bigender, Not specified }
"connections": [2, 4, 6] // represents a relationship (friends/connection) with other users
}
To build this project you will need:
To run the tests and check if everything is running as expected, you will need:
- Jest v29.7+
After cloning the repo, install all dependencies:
npm i
If you want to run the app locally, it's possible to do in two ways:
using npm
:
npm run serve
using docker
:
docker compose up --build
both ways will serve the API running on http://localhost:3000
or you can specify PORT
environment variable.
It's possible to check all simple test cases (happy path) with jest. Simply run:
npm run tests
The base url is primary http://localshost:3000
and primary path is mostly /users
:
List all users:
GET /users
Get users by filter - it's possible to filter from first name, last name and email:
GET /users?filter=string
Add new user:
POST /users
Content-Type: application/json
{
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@doe.com",
"gender": "Female",
"connections": [2, 4, 6]
}
Get single user by id
:
GET /users/:id
Uptade user of id
:
PUT /users/:id
{
"last_name": "Smith",
"connections": [2, 4, 6, 8]
}
Remove user of id
:
DELETE /users/:id
Get relationship distance from one user with id1
to another user with id2
, based on Djisktra algorithm:
GET /users/relationships/:id1-:id2