My API implementation to support the Trial Project described in this link.
The entire API runs on Node.js and is fully written in TypeScript.
It utilizes MongoDB for fetching and storing of data, which is being ran in docker. (see docker-compose.yml
)
It follows the Route-Controller-Service structure for ExpressJS.
Node version used: v16.19.0.
docker compose up -d
npm install
npm test
npm run build
npm run dev
npm run seed:admin
The API endpoints' request and response are described below. Though I highly suggest to check the test cases ./test
as it already serves as a good documentation.
POST /register
localhost:3000/register
{
"email": "[email protected]",
"password": "password"
}
201
{
"message": "Account successfully created."
}
POST /login
localhost:3000/login
{
"email": "[email protected]",
"password": "password"
}
200
{
"message": "Login successful."
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImUxNmU3NzU4LWU1YTYtNDFlNy1iYmM2LTMzNWI1NTgyZTI0YyIsInJvbGUiOiJBRE1JTiIsImlhdCI6MTY3NDg3MTI0OSwiZXhwIjoxNjc0ODcxODQ5fQ.LbcqSk6bOT8TTGgiobLG9TW_KLkwv-f9ospclanAScQ"
}
POST /users/add
localhost:3000/users/add
"authorization": "Bearer token..."
{
"email": "[email protected]",
"password": "password",
"role: "ADMIN"
}
201
{
"message": "User successfully created."
}
GET /users
localhost:3000/users
"authorization": "Bearer token..."
200
{
"users": [
"id": "1..."
"email": "[email protected]"
"password": "hashed..."
"role": "ADMIN"
]
}
PUT /users/update/:id
localhost:3000/users/update/1...
"authorization": "Bearer token..."
{
"email": "[email protected]",
}
200
{
"message": "User successfully updated."
}
DELETE /users/delete/:id
localhost:3000/users/update/1...
"authorization": "Bearer token..."
200
{
"message": "User successfully deleted."
}
POST /recipes/add
localhost:3000/recipes/add
"authorization": "Bearer token..."
{
"name": "name1",
"ingredients": "ingredients1",
"instructions: "instructions1"
}
201
{
"message": "Recipe successfully created."
}
GET /recipes
localhost:3000/recipes
"authorization": "Bearer token..."
200
{
"recipes": [
"id": "1..."
"name": "name1",
"ingredients": "ingredients1",
"instructions: "instructions1",
"createdBy": "1..."
]
}
PUT /recipes/update/:id
localhost:3000/recipes/update/1...
"authorization": "Bearer token..."
{
"name": "updatedname",
}
200
{
"message": "Recipe successfully updated."
}
DELETE /recipes/delete/:id
localhost:3000/users/recipe/1...
"authorization": "Bearer token..."
200
{
"message": "Recipe successfully deleted."
}