This is a NodeJS application with endpoints that allow managing books in a MongoDB database. The application aims to provide a set of operations that can be performed in a library.
To configure the application, follow the instructions below:
- Clone the repository.
- Install the dependencies by running the command npm install.
- Copy the .env.example file to .env and adjust the variables according to your environment's settings.
- Create a db named "library" in your MongoDB in cases where you are running local and not docker through docker-compose
To run the application, execute the command npm start.
All requests require authentication by providing a JWT token obtained through the POST /login endpoint. The token must be sent as a Bearer Token in the headers of subsequent requests.
Checks if the application is responding.
Input parameters
No input parameters required.
Returns
Returns a 'pong' message.
Generates a JWT token for use in other endpoints.
Body
Parameter | Type | Description |
---|---|---|
password | string | Application password. |
Returns
Returns a JWT token.
Returns all books.
Authorization
Parameter | Type | Description |
---|---|---|
Authorization Bearer Token | string | JWT token returned from /login. |
Input parameters
No input parameters required.
Returns
Returns an array with all books.
Checks if the book is available.
Authorization
Parameter | Type | Description |
---|---|---|
Authorization Bearer Token | string | JWT token returned from /login. |
Input parameters
Parameter | Type | Description |
---|---|---|
id | string | Book ID. |
Returns
Returns an message, which indicates if the book is available.
Returns a specific book.
Authorization
Parameter | Type | Description |
---|---|---|
Authorization Bearer Token | string | JWT token returned from /login. |
Input parameters
Parameter | Type | Description |
---|---|---|
id | string | Book ID. |
Returns
Returns an object with the book information.
Creates a new book.
Authorization
Parameter | Type | Description |
---|---|---|
Authorization Bearer Token | string | JWT token returned from /login. |
Body
Parameter | Type | Description |
---|---|---|
title | string | Book title. |
author | string | Book author. |
Returns
Returns an object with the created book information.
Updates an existing book.
Authorization
Parameter | Type | Description |
---|---|---|
Authorization Bearer Token | string | JWT token returned from /login. |
Input parameters
Parameter | Type | Description |
---|---|---|
id | string | Book ID. |
Body
Parameter | Type | Description |
---|---|---|
title | string | Book title. |
author | string | Book author. |
borrower | string | Borrower's name, but NOT REQUIRED if just editing title and author. |
Returns
Returns an object with the updated book information.
Deletes a book.
Authorization
Parameter | Type | Description |
---|---|---|
Authorization Bearer Token | string | JWT token returned from /login. |
Input parameters
Parameter | Type | Description |
---|---|---|
id | string | Book ID. |
Returns
Returns an object with the deleted book information.
- This application has a Dockerfile and docker-compose.yml, run the command docker-compose up -d in the project root.
- This application uses .eslintrc.json and .prettierrc.json.
- This application follows the Model-View-Controller (MVC) pattern and uses SOLID practices.