An open API service indexing awesome lists of open source software.

https://github.com/subramanyamchoda/bookstore-api

Bookstore API is a RESTful service built with Node.js and Express that allows users to manage books with secure JWT-based authentication and JSON file-based storage. It supports user registration, login, and full CRUD operations on books.
https://github.com/subramanyamchoda/bookstore-api

backend bookstoreapp expressjs javascript json jwt-authentication node-js

Last synced: about 2 months ago
JSON representation

Bookstore API is a RESTful service built with Node.js and Express that allows users to manage books with secure JWT-based authentication and JSON file-based storage. It supports user registration, login, and full CRUD operations on books.

Awesome Lists containing this project

README

          

# ๐Ÿ“š Bookstore API

A simple REST API for managing books using **Node.js**, **Express**, and **JSON file storage**.

This app includes:

* ๐Ÿ” User Registration & Login
* ๐Ÿ›ก๏ธ JWT Authentication
* ๐Ÿ“š Book CRUD operations
* ๐Ÿ” Search by Genre
* ๐Ÿ“„ Pagination
* ๐Ÿงพ Token-based access control

---
## ๐Ÿš€ Live URL: [https://bookstore-api-k7a3.onrender.com](https://bookstore-api-k7a3.onrender.com)

Use this URL as the base for all API requests.

---

## ๐Ÿ“ฌ API Endpoints (Ready for Postman)

**Base URL:** `http://localhost:5000`

---

## โœ… User Authentication

### ๐Ÿ“ Register

**POST** `/users/register`

**Request Body:**

```json
{
"email": "subbu@gmail.com",
"password": "subbu"
}
```

### ๐Ÿ” Login

**POST** `/users/login`

**Request Body:**

```json
{
"email": "subbu@gmail.com",
"password": "subbu"
}
```

**Response Example:**

```json
{
"message": "Login successful",
"token": ""
}
```

Copy the token and use it in the **Authorization header** for all `/books` routes:

```
Authorization: Bearer
```

---

## ๐Ÿ“š Book Routes (Protected with JWT)

*All routes below require an auth token.*

### โž• Add Book

**POST** `/books`

**Headers:**

```
Authorization: Bearer
```

**Request Body:**

```json
{
"title": "Node.js Design Patterns",
"author": "Mario Casciaro",
"genre": "Programming",
"publishedYear": 2020
}
```

---

### ๐Ÿ“š Get All Books (with Pagination)

**GET** `/books?page=1&limit=5`

**Response:**

```json
{
"total": 2,
"page": 1,
"limit": 5,
"books": [
{
"id": "36a84b45-1ac7-476b-a0d7-a9cb4af872ad",
"title": "Node.js Design Patterns",
"author": "Mario Casciaro",
"genre": "Programming",
"publishedYear": 2020,
"userId": "13669048-6d2b-4f8e-8991-98ef4a1d935b"
}
]
}
```

---

### ๐Ÿ” Search Books by Genre

**GET** `/books/search?genre=Programming`

---

### ๐Ÿ“– Get Book by ID

**GET** `/books/:id`
*Example:* `/books/36a84b45-1ac7-476b-a0d7-a9cb4af872ad`

---

### โœ๏ธ Update Book

**PUT** `/books/:id`

**Headers:**

```
Authorization: Bearer
```

**Request Body:**

```json
{
"title": "Node Design Patterns",
"author": "Mario Casciaro",
"genre": "Programming",
"publishedYear": 2021
}
```

---

### ๐Ÿ—‘๏ธ Delete Book

**DELETE** `/books/:id`

**Headers:**

```
Authorization: Bearer
```

---

## ๐Ÿ›  Setup Instructions

### ๐Ÿ” Clone the Repository

```bash
git clone https://github.com/subramanyamchoda/bookstore-api.git
cd bookstore-api
```

### ๐Ÿ“ฆ Install Dependencies

```bash
npm install
```

### ๐Ÿ” Environment Variables

Create a `.env` file in the root directory:

```ini
SECRET_KEY=your_secret_key_here
PORT=5000
```

### โ–ถ๏ธ Run the Server

```bash
npm start
```

API will be running at:
๐Ÿ‘‰ `http://localhost:5000`

---

## ๐Ÿ›  Tech Stack

* Node.js
* Express.js
* JWT (jsonwebtoken)
* bcryptjs
* uuid
* File system (JSON file storage)
* Postman (API testing)

---

## โœ… Features

* ๐Ÿ”’ Secure User Registration & Login
* ๐Ÿ›ก JWT-based Protected Routes
* ๐Ÿ“š Full Book Management (Create, Read, Update, Delete)
* ๐Ÿ” Search Books by Genre
* ๐Ÿ“ƒ Pagination for Book Listings
* ๐Ÿ‘ค Only the user who created a book can update/delete it

---

## ๐Ÿ“ธ Postman Testing Screenshots

| Register | Login |
| -------------------------------------------- | ----------------------------------------- |
| | |

| Add Book | Get All Books |
| ------------------------------------------- | ----------------------------------------------- |
| | |

| Single Book | Update Book | Delete Book |
| ---------------------------------------------- | ---------------------------------------------- | ---------------------------------------------- |
| | | |

---

## ๐Ÿ™Œ Reach me

**Subramanyam Choda**
๐Ÿ“ง [Email](mailto:your-email@example.com)
๐ŸŒ [GitHub](https://github.com/subramanyamchoda)