Book Store API Documentation

Welcome to the Book Store API documentation. This page shows the available endpoints for the Book Store API.

Base URL

All endpoints are relative to: https://books-b.netlify.app/.netlify/functions/api

Note: For convenience, many endpoints can also be accessed without the /.netlify/functions/api prefix.

Endpoints

GET /books

Get all books. You can also use /api/books for backward compatibility.

Query Parameters:

Example Response:

[{
  "_id": "60d21b4667d0d8992e610c85",
  "title": "The Book Title",
  "author": "Author Name",
  "price": 19.99,
  "image": "https://example.com/book.jpg",
  "description": "Book description here",
  "category": ["fiction", "adventure"]
}]

GET /books/:id

Get a specific book by its ID. You can also use /api/books/:id.

Example Response:

{
  "_id": "60d21b4667d0d8992e610c85",
  "title": "The Book Title",
  "author": "Author Name",
  "price": 19.99,
  "image": "https://example.com/book.jpg",
  "description": "Book description here",
  "category": ["fiction", "adventure"]
}

GET /slok/:chapter/:slok

Get a specific Bhagavad Gita slok. You can also use /api/slok/:chapter/:slok.

Example Response:

{
  "_id": "BG1.1", 
  "chapter": 1, 
  "verse": 1, 
  "slok": "dharma-kṣetre kuru-kṣetre samavetā yuyutsavaḥ...", 
  "transliteration": "dharma-kṣetre kuru-kṣetre...", 
  "tej": { "ht": "धर्मक्षेत्रे कुरुक्षेत्रे..." },
  "translations": { "en": "Observing the armies..." }
}

POST /auth/login

Authenticate a user. You can also use /api/auth/login.

Request Body:

{
  "email": "user@example.com",
  "password": "password123"
}

Example Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": "60d21b4667d0d8992e610c85",
    "name": "User Name",
    "email": "user@example.com",
    "isAdmin": false
  }
}

POST /books/create-book

Create a new book (requires admin authentication). You can also use /api/books/create-book.

Request Headers:

Authorization: Bearer YOUR_TOKEN

Request Body:

{
  "title": "New Book Title",
  "author": "Author Name",
  "price": 24.99,
  "image": "https://example.com/new-book.jpg",
  "description": "Description of the new book",
  "category": ["fiction", "mystery"]
}

Error Handling

All endpoints will return appropriate HTTP status codes and JSON error messages in case of failure.

For any issues or questions about the API, please contact the administrator.