Live deploy link :- https://bookstore-ojh2zrcab-pintu870s-projects.vercel.app/api/books
# CRUD API with Authentication
This is a CRUD (Create, Read, Update, Delete) API with user authentication using JSON Web Tokens (JWT). It allows users to register, login, and perform CRUD operations on books.
## Features
- User registration
- User login with JWT authentication
- Get current user profile
- Create, read, update, and delete books
## Technologies Used
- Node.js
- Express.js
- MongoDB
- Mongoose
- JSON Web Tokens (JWT)
- bcrypt.js
- dotenv
## Getting Started
### Prerequisites
Make sure you have Node.js and MongoDB installed on your machine.
### Installation
1. Clone the repository:
```bash
git clone https://github.com/pintu544/Bookstore
-
Install dependencies:
cd Bookstore npm install
-
Set environment variables:
Create a
.env
file in the root directory of your project. Add the following environment variables:MONGO_URI=mongodb://localhost:27017/your_database PORT=3000 JWT_SECRET=your_secret_key
-
Run the application:
npm start
-
URL:
/api/auth/register
-
Method:
POST
-
Request Body:
{ "username": "your_username", "password": "your_password" }
-
Response:
{ "_id": "user_id", "username": "your_username", "token": "your_jwt_token" }
-
URL:
/api/auth/login
-
Method:
POST
-
Request Body:
{ "username": "your_username", "password": "your_password" }
-
Response:
{ "_id": "user_id", "username": "your_username", "token": "your_jwt_token" }
- URL:
/api/books
- Method:
GET
- Authentication: Required
- URL:
/api/books/:id
- Method:
GET
- Authentication: Required
-
URL:
/api/books
-
Method:
POST
-
Authentication: Required
-
Request Body:
{ "title": "book_title", "author": "book_author", "publicationYear": 2022, "isbn": "book_isbn" }
-
URL:
/api/books/:id
-
Method:
PUT
-
Authentication: Required
-
Request Body:
{ "title": "updated_book_title", "author": "updated_book_author", "publicationYear": 2023, "isbn": "updated_book_isbn" }
- URL:
/api/books/:id
- Method:
DELETE
- Authentication: Required