Code Monkey home page Code Monkey logo

topshelfre's Introduction

Book Store API

Hoping this reaches you, I added functionality to this file along with added 2 files separating the app portion from the testing suite. Description

This project is a simple Book Store API built with Node.js and Express. It allows you to perform CRUD operations on a collection of books. Each route is wrapped in a try-catch block to handle errors gracefully. Endpoints HTTP.METHOD = GET

Function: Retrieve all books /Books section and relevant tests:

Retrieves all records. If successful, returns 200 and the records. If an error occurs, returns 500.
Test: Ensures that GET /books returns a 200 status and an array of books. If the array is empty, it returns an empty array.

HTTP.METHOD = GET

Function: Retrieve book by ID /Books/:id section and relevant tests:

Retrieves a book by ID. If the book is found, returns 200 and the book. If not found, returns 404. If an error occurs, returns 500.
Test: Ensures that GET /books/:id returns a 200 status and the book with the matching ID if found. If the book is not found, returns a 404 status with 'Book not found' message.

HTTP.METHOD = POST

Function: Add a new book /Books section and relevant tests:

Adds a new book. If successful, returns 201 and the new book. If req.body is missing or invalid, returns 400.
Test: Ensures that POST /books adds a new book to the collection, returns a 201 status, and the newly added book. If req.body is missing or invalid, returns a 400 status.

HTTP.METHOD = PUT

Function: Update book by ID /Books/:id section and relevant tests:

Updates a book by ID. If successful, returns 200 and the updated book. If the book ID is not found, returns 404. If an error occurs, returns 500.
Test: Ensures that PUT /books/:id updates the book with the given ID and returns the updated book. If the book ID does not exist, it returns a 404 status. Validates that the update data is correctly applied to the book.

HTTP.METHOD = DELETE

Function: Delete book by ID /Books/:id section and relevant tests:

Deletes a book by ID. If successful, returns 200 and a 'Book deleted' message. If the book ID is not found, returns 404. If an error occurs, returns 500.
Test: Ensures that DELETE /books/:id deletes the book with the given ID, returns a 200 status, and a message 'Book deleted'. If the book ID does not exist, it returns a 404 status.

Setup Instructions Prerequisites

Node.js and npm installed
Git installed

Install dependencies:

npm install

Running the Application

Start the server:

  node app.js

The server will be running on http://localhost:3000.

Run the tests:

npm test

Running in VSCode

Open the project folder in VSCode.
Make sure you have the necessary extensions installed 
Use the integrated terminal to run the above commands for starting the server and running tests.

Containerization:

Create a Dockerfile:

 Dockerfile

 WORKDIR /app

 COPY package*.json ./
 RUN npm install

 COPY . .

 EXPOSE 3000
 CMD ["node", "app.js"]

Build the Docker image:

docker build -t book-store-api .

Run the Docker container:

docker run -p 3000:3000 book-store-api

The server will be running on http://localhost:3000.

topshelfre's People

Contributors

varunturlapati avatar tedy97123 avatar

Stargazers

Constantine Zavezeon 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.