Skip to content

Repository files navigation

Bookstore API

A RESTful API for a Bookstore Application built with NestJS, TypeScript, and MongoDB.

Features

  • User Authentication (JWT-based)
  • Books CRUD operations
  • Filtering & Search functionality
  • Error handling and validation
  • Pagination and sorting
  • API Documentation

Tech Stack

  • Language: TypeScript
  • Framework: NestJS
  • Database: MongoDB
  • ORM: Mongoose
  • Authentication: JWT

Setup Instructions

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn
  • MongoDB (local or Atlas)

Installation

  1. Clone the repository
  2. Install dependencies:
    npm install
  3. Create a .env file 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
    
  4. Start the application:
    npm run start:dev

API Endpoints

Authentication

  • POST /auth/signup - Register a new user
  • POST /auth/login - Login and get JWT token

Books

  • GET /books - Get all books (with optional filtering, pagination, and sorting)
  • GET /books/:id - Get a specific book by ID
  • POST /books - Create a new book (protected)
  • PUT /books/:id - Update a book (protected)
  • DELETE /books/:id - Delete a book (protected)

Sample Requests

User Signup

POST /auth/signup
Content-Type: application/json

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

User Login

POST /auth/login
Content-Type: application/json

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

Create Book

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 with Filtering

GET /books?author=Fitzgerald&category=Fiction&rating=4.5&page=1&limit=10&sortBy=price&sortOrder=asc

Search Books by Title

GET /books?search=Great

About

A RESTful API for a Bookstore Application built with NestJS, TypeScript, and MongoDB.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages