Skip to content

AlexKlim/book-management-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Book Management API

A RESTful API for book management, built with Node.js, Express, and MongoDB.

🚀 Technologies Used

  • Node.js
  • Express
  • MongoDB with Mongoose
  • Cors
  • Morgan
  • Dotenv

📂 Project Structure

/book-management-api
│-- /config
│   ├── db.js               # Database configuration
│-- /models
│   ├── Book.js             # Book model
│-- /routes
│   ├── bookRoutes.js       # Route definitions
│-- /controllers
│   ├── bookController.js   # Request controllers
│-- /services
│   ├── bookService.js      # Business logic
│-- server.js               # Server initialization
│-- package.json            # Project dependencies
│-- .env                    # Environment settings

📌 Prerequisites

  1. Install Node.js: Download Node.js
  2. Install MongoDB (locally or use MongoDB Atlas)
  3. Clone the repository:
    git clone <REPO_URL>
    cd book-management-api

🛠️ Installation and Execution

1️⃣ Install Dependencies

npm install

2️⃣ Create a .env file

Create a .env file in the project's root and add:

MONGO_URI=mongodb://localhost:27017/bookstore
PORT=5000

3️⃣ Start the Server

npm start

Or, for development with automatic restarts:

nodemon server.js

🔥 API Endpoints

The API exposes the following endpoints:

📌 Create a Book (POST)

POST /api/books

JSON Body:

{
  "title": "The Great Gatsby",
  "author": "F. Scott Fitzgerald",
  "publishedYear": 1925,
  "genre": "Classic"
}

📌 Get All Books (GET)

GET /api/books

📌 Get a Book by ID (GET)

GET /api/books/:id

📌 Update a Book (PUT)

PUT /api/books/:id

JSON Body:

{
  "title": "New Title"
}

📌 Delete a Book (DELETE)

DELETE /api/books/:id

🧪 Testing the API

You can test the API using Postman, Insomnia, or curl commands in the terminal.

Example:

curl -X GET http://localhost:5000/api/books

📜 License

This project is open-source and free to use.


🚀 Developed with Node.js and MongoDB

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors