Coder Social home page Coder Social logo

bms's Introduction

# Books API
##Project details
Project description: An api that manages books along with authors.
Author: Nwinyinya David (the-last_php_bender)
Email: [email protected]

## Project Setup

1. **Clone the repository**:
   ```bash
   git clone <repository_url>
   cd books-api
  1. Install dependencies:

    npm install
  2. Set up the .env file:

    MONGO_URI=your_mongodb_connection_string
    PORT=5000
    
  3. Start the application:

    npm start

API Endpoints

  • Create a Book: POST /api/books

    • Request Body:
      {
        "title": "string",
        "author": "string",
        "publishedDate": "date",
        "ISBN": "string"
      }
    • Response:
      {
        "_id": "string",
        "title": "string",
        "author": "string",
        "publishedDate": "date",
        "ISBN": "string"
      }
  • Get All Books: GET /api/books

    • Response:
      [
        {
          "_id": "string",
          "title": "string",
          "author": "string",
          "publishedDate": "date",
          "ISBN": "string"
        }
      ]
  • Get a Single Book: GET /api/books/:id

    • Response:
      {
        "_id": "string",
        "title": "string",
        "author": "string",
        "publishedDate": "date",
        "ISBN": "string"
      }
  • Update a Book: PUT /api/books/:id

    • Request Body:
      {
        "title": "string",
        "author": "string",
        "publishedDate": "date",
        "ISBN": "string"
      }
    • Response:
      {
        "_id": "string",
        "title": "string",
        "author": "string",
        "publishedDate": "date",
        "ISBN": "string"
      }
  • Delete a Book: DELETE /api/books/:id

    • Response:
      {
        "message": "Book deleted successfully"
      }
  • Update Book Cover: PATCH /api/books/cover-image/:id

    • Request Body: FormData with field coverImage
    • Response:
      {
        "_id": "string",
        "title": "string",
        "author": "string",
        "publishedDate": "date",
        "ISBN": "string",
        "coverImage": "string"
      }

Testing

To run tests:

npm test

Test Example

  • Install testing libraries:

    npm install jest supertest ts-jest @types/jest @types/supertest --save-dev
  • Configure Jest in package.json:

    "jest": {
      "preset": "ts-jest",
      "testEnvironment": "node",
      "testPathIgnorePatterns": ["/node_modules/"]
    }

Directory Structure

books-api/
├── src/
│   ├── controllers/
│   │   └── bookController.ts
│   ├── models/
│   │   └── book.ts
│   ├── routes/
│   │   └── bookRoutes.ts
│   ├── middlewares/
│   │   └── upload.ts
│   ├── utils/
│   │   └── db.ts
│   └── app.ts
├── .env
├── .gitignore
├── package.json
├── README.md
└── tsconfig.json

Notes

  • Ensure you have MongoDB running locally or use a cloud-based MongoDB service.
  • The uploads/ directory is where the book cover images will be stored. Ensure this directory exists or create it in your project root.
  • Modify the MONGO_URI in your .env file to match your MongoDB connection string.

bms's People

Contributors

the-last-php-bender avatar

Watchers

 avatar

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.