A RESTful API for a Bookstore Application built with NestJS, TypeScript, and MongoDB.
- User Authentication (JWT-based)
- Books CRUD operations
- Filtering & Search functionality
- Error handling and validation
- Pagination and sorting
- API Documentation
- Language: TypeScript
- Framework: NestJS
- Database: MongoDB
- ORM: Mongoose
- Authentication: JWT
- Node.js (v14 or higher)
- npm or yarn
- MongoDB (local or Atlas)
- Clone the repository
- Install dependencies:
npm install
- Create a
.envfile in the root directory with the following variables:MONGODB_URI=mongodb://localhost:27017/bookstore JWT_SECRET=your_jwt_secret_key JWT_EXPIRATION=1d PORT=3000 - Start the application:
npm run start:dev
POST /auth/signup- Register a new userPOST /auth/login- Login and get JWT token
GET /books- Get all books (with optional filtering, pagination, and sorting)GET /books/:id- Get a specific book by IDPOST /books- Create a new book (protected)PUT /books/:id- Update a book (protected)DELETE /books/:id- Delete a book (protected)
POST /auth/signup
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}POST /auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}POST /books
Content-Type: application/json
Authorization: Bearer <jwt_token>
{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"category": "Fiction",
"price": 12.99,
"rating": 4.5,
"publishedDate": "1925-04-10"
}GET /books?author=Fitzgerald&category=Fiction&rating=4.5&page=1&limit=10&sortBy=price&sortOrder=ascGET /books?search=Great