A RESTful API for a book store with user authentication, book management, reviews, and server-side token revocation. Built using Node.js, Express.js, TypeScript, and MongoDB.
- User authentication with JWT tokens.
- CRUD operations for books (Create, Read, Update, Delete).
- Users can add, edit, and delete reviews for books.
- Books have unique ISBNs for identification.
- Partial search for books by title, author, or ISBN.
- Node.js (>=14.x)
- MongoDB (running locally or a remote MongoDB service)
- Git (optional)
- Clone the repository (if you haven't already):
git clone https://github.com/CaiqueSobral/BookStoreNodeAPI.git
- Change to the project directory:
cd bookstorenodeapi
- Install dependencies:
npm install
-
Configure the environment variables in a
.env
file (see JWT Token for details). -
Start the server:
npm run start:dev
-
Users must register and log in to access protected routes.
-
Authentication is implemented using JSON Web Tokens (JWT). Users receive a JWT token upon successful login, which they must include in the Authorization header of subsequent requests.
-
Register:
/api/user/register
(POST) -
Login:
/api/user/login
(POST)
- Get All Books:
/api/books
(GET) - Get Book by ISBN:
/api/books/isbn/:isbn
(GET) - Get Books by Author:
/api/books/author/:author
(GET) - Get Books by Title:
/api/books/title/:title
(GET) - Add a New Book:
/api/books
(POST) - Update a Book:
/api/books/:bookId
(PUT) - Delete a Book:
/api/books/:bookId
(DELETE)
- Get All Reviews:
/api/reviews/books
(GET) - Get Review by ID:
/api/reviews/:reviewId
(GET) - Add a New Review:
/api/reviews/books/:bookId
(POST) - Update a Review:
/api/reviews/:reviewId
(PUT) - Delete a Review:
/api/reviews/:reviewId
(DELETE)
- MongoDB is used as the database to store books, users, and reviews.
- Books have a unique ISBN for identification.
- Users have authentication credentials stored securely.
- Reviews are associated with books and users.
- The API exposes various endpoints for book and review management.
- JSON Web Tokens (JWT) are used for user authentication.
- A secret key is used to sign and verify JWT tokens.
- Users receive a JWT token upon successful login.
- The token must be included in the Authorization header for authentication.
Contributions are welcome! Feel free to open issues or submit pull requests to improve this project.