Coder Social home page Coder Social logo

booksapi's Introduction

Books API

Welcome to the Books API! This is a simple RESTful API built with Node.js, Express, and MongoDB that allows you to manage a collection of books. You can create, read, update, and delete book records.

Table of Contents

Features

  • Create: Add new books to the collection.
  • Read: Retrieve a list of all books or details of a specific book by ID.
  • Update: Modify the details of an existing book.
  • Delete: Remove a book from the collection.

Installation

Follow these steps to set up the project locally:

  1. Clone the Repository

    git clone https://github.com/AthulKM/booksAPI.git
    cd booksAPI
  2. Install Dependencies

    Ensure you have Node.js and npm installed. Install the required dependencies:

    npm install
  3. Set Up Environment Variables

    Create a .env file in the root directory of the project and add your MongoDB URI:

    MONGO_URI=your_mongodb_connection_string
    PORT=3000
    
  4. Run the Application

    Start the server:

    npm start

    The server will run on http://localhost:3000 by default.

Usage

Once the server is running, you can interact with the API using tools like Postman or curl.

Example Requests

  • Create a Book

    curl -X POST http://localhost:3000/books -H "Content-Type: application/json" -d '{"title": "The Hobbit", "author": "J.R.R. Tolkien", "publishedYear": 1937, "genre": "Fantasy", "pages": 310}'
  • Get All Books

    curl http://localhost:3000/books
  • Get a Book by ID

    curl http://localhost:3000/books/<book_id>
  • Update a Book by ID

    curl -X PUT http://localhost:3000/books/<book_id> -H "Content-Type: application/json" -d '{"title": "Updated Title"}'
  • Delete a Book by ID

    curl -X DELETE http://localhost:3000/books/<book_id>

API Endpoints

  • POST /books: Create a new book.
  • GET /books: Retrieve all books.
  • GET /books/:id: Retrieve a book by ID.
  • PUT /books/:id: Update a book by ID.
  • DELETE /books/:id: Delete a book by ID.

Technologies

  • Node.js: JavaScript runtime for building server-side applications.
  • Express: Web framework for Node.js.
  • MongoDB: NoSQL database for storing book records.
  • Mongoose: ODM library for MongoDB and Node.js.
  • dotenv: Module to load environment variables from a .env file.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes.

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Make your changes and commit them.
  4. Push your changes to your fork.
  5. Create a pull request describing your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Thank You ☺️

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.