This is simple CRUD API for managing users entities.
You need to clone or fork this repository and run:
npm install
to install all dependencies.
Install DB PostgreSQL on your machine or use a free web hosting services for PostgreSQL (https://www.heroku.com/postgres or https://www.elephantsql.com/plans.html).
Rename .env.example file to .env. You need to change .env file and provide your PostgreSQL database credentials.
To create database you can run :
npm run db:create
# development
npm run start:dev
# production
npm run start:prod
# build
npm run build
Application starts on PORT 3000 (you can change this in .env file), default URL http://localhost:3000
You can use Postman to send requests to server. All endpoints (except POST /v1/auth/login and POST /v1/users) are protected, that means you need authorize (login) and provide token with "Authorization": "Bearer ${token}" header.
Auth endpoints
Login user. Request should contain body in JSON format. Request body example:
{
"email": "[email protected]",
"password": "12345678qwe"
}
Response example:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI5YjFkZWI0ZC0zYjdkLTRiYWQtOWJkZC0yYjBkN2IzZGNiNmQiLCJpYXQiOjE1MTYyMzkwMjJ9.A7RPWdhfOusPgTTbdZSskLRezAHR4yDzoa2Enyxhwlc"
}
Users endpoints
Create user. Request should contain form-data with fields:
email: string firstName: string lastName: string password: string image: (mime-types for image is PNG, JPG)
Response example:
{
"email": "[email protected]",
"firstName": "Sergey",
"lastName": "Serzhan",
"image": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG...5vdCBvbm",
"pdf": null || Buffer
}
Get all users. Response example:
[
{
"email": "[email protected]",
"firstName": "Sergey",
"lastName": "Serzhan",
"image": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG...5vdCBvbm",
"pdf": null || Buffer
}
]
Get user by email. Request should contain body in JSON format:
{
"email": "[email protected]"
}
Response example:
{
"email": "[email protected]",
"firstName": "Sergey",
"lastName": "Serzhan",
"image": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG...5vdCBvbm",
"pdf": null || Buffer
}
Update existing user by email. Request should contain form-data with fields:
updatedEmail: string
(Notice: all fields above not required)
email: string firstName: string lastName: string password: string image: (mime-types for image is PNG, JPG)
Response example:
{
"email": "[email protected]",
"firstName": "Sergey",
"lastName": "Serzhan",
"image": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG...5vdCBvbm",
"pdf": null || Buffer
}
Delete user by email. Request should contain body in JSON format:
{
"email": "[email protected]"
}
Response with 204 status code No-Content.
Generate pdf for provided user. Request should contain body in JSON format:
{
"email": "[email protected]"
}
Response example:
{
"result": true;
}