- Local:
http://localhost:8000/api - Production:
https://bookbazaar-zy9o.onrender.com/api
Most endpoints require JWT authentication. Include the token in the Authorization header:
Authorization: Bearer <your_jwt_token>
GET /books
Query Parameters:
page(default: 1) - Page numberlimit(default: 12) - Books per pagecategory- Filter by category (Fiction, Non-Fiction, Self-Help, Comics, Science, Biography, Mystery, Romance, Technology, History, Children)minPrice- Minimum pricemaxPrice- Maximum pricerating- Minimum rating (0-5)search- Search in title and authorauthor- Filter by author namesort- Sort by:price-asc,price-desc,rating,latest
Example: /books?category=Fiction&minPrice=10&maxPrice=50&rating=4&sort=rating&page=1
Response:
{
"books": [...],
"page": 1,
"pages": 5,
"total": 60
}GET /books/:id
GET /books/featured
Returns top 8 featured books sorted by rating.
POST /books
Auth: Admin required
Body:
{
"title": "Book Title",
"author": "Author Name",
"description": "Book description",
"isbn": "1234567890",
"publisher": "Publisher Name",
"publishedDate": "2024-01-01",
"language": "English",
"pages": 300,
"category": "Fiction",
"price": 29.99,
"originalPrice": 39.99,
"discount": 25,
"stock": 100,
"images": ["url1", "url2"],
"featured": false
}PUT /books/:id
Auth: Admin required
DELETE /books/:id
Auth: Admin required
GET /cart
Auth: Required
POST /cart
Auth: Required
Body:
{
"bookId": "book_id_here",
"quantity": 1
}PUT /cart/:bookId
Auth: Required
Body:
{
"quantity": 2
}DELETE /cart/:bookId
Auth: Required
DELETE /cart
Auth: Required
POST /orders
Auth: Required
Body:
{
"shippingAddress": {
"fullName": "John Doe",
"email": "john@example.com",
"address": "123 Main St",
"city": "New York",
"state": "NY",
"zipCode": "10001",
"country": "USA",
"phone": "+1234567890"
},
"paymentMethod": "COD"
}Note: Order is created from current cart items. Cart is automatically cleared after order creation.
GET /orders/my
Auth: Required
Query Parameters:
page(default: 1)limit(default: 10)
GET /orders/:id
Auth: Required (own orders) or Admin
GET /orders
Auth: Admin required
Query Parameters:
page(default: 1)limit(default: 10)status- Filter by status: Pending, Processing, Shipped, Delivered, Cancelled
PUT /orders/:id/status
Auth: Admin required
Body:
{
"status": "Shipped",
"trackingNumber": "TRACK123"
}PUT /orders/:id/pay
Auth: Required
Marks order as paid.
POST /reviews
Auth: Required
Body:
{
"book": "book_id_here",
"rating": 5,
"title": "Amazing book!",
"comment": "This book changed my life..."
}Note: Users can only review each book once. Reviews from verified purchases are marked as verified.
GET /reviews/:bookId
Query Parameters:
page(default: 1)limit(default: 10)
PUT /reviews/:id
Auth: Required (own review)
Body:
{
"rating": 4,
"title": "Updated title",
"comment": "Updated comment"
}DELETE /reviews/:id
Auth: Required (own review) or Admin
POST /reviews/:id/helpful
Auth: Required
Increments the helpful count for a review.
GET /wishlist
Auth: Required
POST /wishlist
Auth: Required
Body:
{
"bookId": "book_id_here"
}DELETE /wishlist/:bookId
Auth: Required
POST /wishlist/toggle
Auth: Required
Body:
{
"bookId": "book_id_here"
}Adds to wishlist if not present, removes if already in wishlist.
DELETE /wishlist
Auth: Required
POST /auth/signup
Body:
{
"name": "John Doe",
"email": "john@example.com",
"password": "securePassword123"
}Response:
{
"token": "jwt_token_here",
"user": {
"_id": "user_id",
"name": "John Doe",
"email": "john@example.com",
"role": "buyer"
}
}POST /auth/login
Body:
{
"email": "john@example.com",
"password": "securePassword123"
}GET /auth/profile
Auth: Required
All endpoints return appropriate HTTP status codes:
- 200 - Success
- 201 - Created
- 400 - Bad Request (validation errors)
- 401 - Unauthorized (not authenticated)
- 403 - Forbidden (not authorized for this action)
- 404 - Not Found
- 500 - Server Error
Error response format:
{
"message": "Error description"
}- Validates cart is not empty
- Checks stock availability for all items
- Calculates totals:
- Subtotal: Sum of (price × quantity)
- Tax: 10% of subtotal
- Shipping: ₹50 (free if subtotal > ₹500)
- Total: Subtotal + Tax + Shipping
- Creates order with denormalized book data
- Decrements book stock
- Clears user's cart
- One review per user per book (compound unique index)
- Automatic book rating calculation
- Verified purchase badge for users who bought the book
- Helpful count for community feedback
- Stock is decremented when order is created
- Cart validates stock before allowing add to cart
- Admin can manage stock via book update endpoint
- Books have price and discount percentage
- Virtual field
discountedPricecalculates: price × (1 - discount/100) - Cart stores price snapshot at time of adding (protects against price changes)