Welcome to the documentation for the Bookstore API. This project aims to provide a RESTful API for managing a a bookstore, including Authors, Customers, Books and Sales. It also provide a way to create reviews under the books.
The purpose of this project was to sum up all of the knowledge obtained across the Node.Js bootcamp of fullstack post graduating of XP Education to prepare to the final integrator project.
It includes migrations of the database, providing schemas and models to facilitate sharing across developer's team. Also have a basic authentication and authorization handling. Uses a structered and ununstructered databases, leveraging MongoDB and PostgreSQL according to the need. It have some integrations's test through Jest and Supertest and it also provide a logging of all of operations performed
To install and set up the project locally, follow these steps:
- Clone the project repository from GitHub:
git clone https://github.com/alefnsc/booktore-api.git- Navigate to the project directory:
cd bookstore-api- Install project dependencies using npm:
npm installAfter installation, you can start the server by running:
npm startThis will start the Express server and make the API available at http://localhost:3000.
To perform tests you can run:
npm testTo try it on the watch mode, just run:
npm run watchCheckout the description, how to use each method, the authorizaton needed, required fields, rules and optional parameters.
- Description: Retrieves all authors.
- Authorization: Requires admin authorization.
- Method: GET
- Description: Retrieves a specific author by their ID.
- Authorization: Requires admin authorization.
- Method: GET
- Description: Creates a new author.
- Authorization: Requires admin authorization.
- Method: POST
- Required Fields: name, email, phone.
- Description: Updates author information.
- Authorization: Requires admin authorization.
- Method: PUT
- Required Fields: id, name, email, phone.
- Description: Deletes an author by their ID.
- Authorization: Requires admin authorization.
- Method: DELETE
- Rule: If the author has associated books. Deletion is not allowed.
- Description: Retrieves all books.
- Authorization: Requires admin or user authorization.
- Method: GET
- Optional Rule: You might use the query parameter "?authorId=" on the URL to retrieve all books of a specific author.
- Description: Retrieves a specific book by its ID.
- Authorization: Requires admin or user authorization.
- Method: GET
- Description: Creates a new book.
- Authorization: Requires admin authorization.
- Method: POST
- Description: Updates book information.
- Authorization: Requires admin authorization.
- Method: PUT
- Required Fields: value.
- Rule: You should not update the book's name and authorId fields
- Description: Deletes a book by its ID.
- Authorization: Requires admin authorization.
- Method: DELETE
- Rule: If the book has associated sales. Deletion is not allowed.
- Description: Creates book's information.
- Authorization: Requires admin authorization.
- Method: POST
- Required Fields: bookId, description, pages, editor.
- Description: Updates book information.
- Authorization: Requires admin authorization.
- Method: PUT
- Required Fields: bookId, description, pages, editor.
- Description: Deletes book information by bookId.
- Authorization: Requires admin authorization.
- Method: DELETE
- Description: Creates a book review.
- Authorization: Requires admin or user authorization.
- Method: POST
- Description: Deletes a book (by bookId) review by its index (starting on 0).
- Authorization: Requires admin authorization.
- Method: DELETE
- Description: Retrieves all customers.
- Authorization: Requires admin authorization.
- Method: GET
- Description: Retrieves a specific customer by their ID.
- Authorization: Requires admin authorization.
- Method: GET
- Description: Creates a new customer.
- Authorization: Requires admin authorization.
- Method: POST
- Required Fields: name, email, password, phone, address
- Description: Updates customer information.
- Authorization: Requires admin authorization.
- Method: PUT
- Required Fields: customerId, name, email, password, phone, address
- Description: Deletes a customer by their ID.
- Authorization: Requires admin authorization.
- Method: DELETE
- Rule: If customer has associated sales. Deletion is not allowed.
- Description: Retrieves all sales.
- Authorization: Requires admin or user authorization.
- Method: GET
- Optional Rule 1: You might use the query parameter "?bookId=" on the URL to retrieve all sales of a specific book.
- Optional Rule 2: You might use the query parameter "?authorId=" on the URL to retrieve all sales of a specific author.
- Optional Rule 3: You might use the query parameter "?customerId=" on the URL to retrieve all sales of a specific customer.
- Description: Retrieves a specific sale by its ID.
- Authorization: Requires admin authorization.
- Method: GET
- Description: Creates a new sale.
- Authorization: Requires admin or user authorization.
- Method: POST
- Description: Updates sale information.
- Authorization: Requires admin authorization.
- Method: PUT
Please make sure to include the required authorization headers when making requests to these routes.
It could be updated on basicAuth
- Username: admin
- Password: desafio-igti-nodejs
-
basic-auth: a library which streamline authentication headers access to facilitate credentials retrieve.
-
jest: Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
-
supertest: Supertest is a Node. js library that allows developers and testers to test the APIs. It enables developers and testers to write automated tests for routes and endpoints.
-
cors: A package that enables Cross-Origin Resource Sharing (CORS) in Express applications, allowing controlled access to resources from different origins.
-
express: A popular web application framework for Node.js used to create APIs and web servers. It simplifies routing, middleware, and handling HTTP requests.
-
mongoose: A MongoDB driver for Node.js, providing methods for interacting with MongoDB databases.
-
nodemon: A tool that monitors changes in your source code and automatically restarts the Node.js application when changes are detected. Great for development.
-
pg: A PostgreSQL client for Node.js that enables you to interact with PostgreSQL databases.
-
sequelize: A promise-based Node.js ORM (Object-Relational Mapping) for relational databases like PostgreSQL, MySQL, SQLite, etc.
-
winston: A popular logging library for Node.js that offers flexible and configurable logging options.
- Maintainer: Alexandre Fonseca
- Email: alexandrefonsecach@gmail.com