This is a sample API for a book library.
Development environment: Node v17.6.0 (lower versions can be used)
npm install
npm run dev
Configuration settings are in the environment variables file .env
.
GET /users
GET /users/:id
PATCH /users/:id
DELETE /users/:id
GET /books
GET /books/:id
POST /books
PATCH /books/:id
DELETE /books/:id
POST /books/:id/borrow
(borrow a book)
POST /books/:id/return
(return a book)
Requests must be authenticated with a valid user token sent in the header.
Authentication is done via the Authorization
header:
Authorization: Bearer <user_token>
To get a user token, you can use the /auth/login
endpoint.
Before you can use the API, you need to create a user.
POST /auth/signup
{
"name": "John Doe",
"email": "[email protected]",
"password": "123456"
}
POST /auth/login
{
"email": "[email protected]",
"password": "123456",
}
POST /auth/activate/:code
Activation code is sent to the user email address or can be seen in the users list endpoint which is not protected by authentication.
After activation, you can login and get a user token and use it to borrow and return books.