Skip to content

Kanha1235/book_catalog_api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Book Catalog API

A secure and scalable RESTful Book Catalog API built using Node.js, Express.js (ES Modules) and MongoDB, implementing authentication using HTTP-only cookies instead of authorization headers.

The project follows a clean MVC architecture with modular route structure and secure middleware practices.

🌐 Live API

https://book-catalog-api-rx65.onrender.com/


🚀 Features

  • 🔐 User Authentication (Register / Login / Logout)
  • 🍪 JWT stored in HTTP-only cookies
  • 📖 Add, Update, Delete, Get Books
  • 👤 User-specific book management
  • 🧱 Modular folder structure
  • ⚡ Rate limiting for security
  • 🛡️ Password hashing using bcrypt
  • 🌍 RESTful API design
  • 🧪 Fully tested with Postman

🏗️ Tech Stack

  • Node.js
  • Express.js (ES Module Type)
  • MongoDB + Mongoose
  • JWT (JSON Web Token)
  • bcrypt
  • cookie-parser
  • express-rate-limit

📂 Project Structure

book-catalog-api

├── configs
│ └── db.config.js
│ └── env.config.js

├── controllers
│ ├── user.controller.js
│ └── book.controller.js

├── middlewares
│ ├── auth.middleware.js
│ └── error.middleware.js

├── models
│ ├── user.model.js
│ └── book.model.js

├── routes
│ ├── user.route.js
│ └── book.route.js

├── utils
│ ├── generateToken.util.js

├── .env
├── index.js
└── package.json\


🔐 Authentication Flow (Cookie Based)

  1. User logs in
  2. Server generates JWT
  3. JWT stored in HTTP-only cookie
  4. Protected routes verify cookie token
  5. No Authorization header used

📌 API Endpoints

👤 User Routes

Method Endpoint Description
POST /api/users/register Register user
POST /api/users/login Login user

📚 Book Routes

Method Endpoint Description
POST /api/books Add new book
GET /api/books Get all books (user-specific)
GET /api/books/:id Get single book
PUT /api/books/:id Update book
DELETE /api/books/:id Delete book

🛡️ Security Implementations

  • HTTP-only cookies (prevents XSS attacks)
  • Password hashing with bcrypt
  • Rate limiting (100 requests / 15 min)
  • Centralized error handling
  • JWT verification middleware

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors