Skip to content

Server-side REST API that serves requests from Frontend App

Notifications You must be signed in to change notification settings

Tam643/BookStoreAPI

Repository files navigation

Contributors Forks Stargazers Issues LinkedIn


BookStoreAPI

This is a basic REST API skeleton written on Javascript.
Great for building a starter web API for your front-end
(Vue, React, Angular, or anything that can consume an API).

Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Usage
  5. Contact
  6. Acknowledgments

About the project

The BookStoreAPI project aims to offer a foundation for building a fully-fledged virtual bookstore application. By following this API, developers can easily set up book-related operations, manage orders, generate bills, and secure routes using authentication. This project showcases best practices for API design, data modeling, and user authentication in a practical context.

Features

  • Book Management:
    • Create, retrieve, update, and delete book records.
    • View details of individual books.
  • User Authentication:
    • User registration with unique authentication tokens.
    • Secure login and token-based authentication for protected routes.
    • Role-Based Access Control (RBAC) is help control what different users can do within the system.
  • Order Processing:
    • Create and manage customer orders.
    • View order history for users.
  • Order Bill Generation:
    • Generate detailed order bills with transaction information.

(back to top)

Built With

  • Expressjs-shield
  • Formidable-shield
  • fs-extra-shield
  • Joi-shield
  • Mongoose-shield
  • Argon2-shield

(back to top)

Getting Started

Prerequisites

Before setting up a Node.js application with Docker and MongoDB, you need to ensure that you have the necessary prerequisites in place. Below are the prerequisites for setting up this environment:

  1. Node.js and npm:

    • Node.js: You should have Node.js installed on your system. You can download it from the official Node.js website: https://nodejs.org/
    • npm (Node Package Manager): npm is usually included with Node.js. You can verify its installation by running npm -v in your terminal.
  2. Docker:

    • Docker Desktop (for Windows and macOS): If you are using Windows or macOS, install Docker Desktop, which includes both Docker Engine and Docker Compose. You can download it from the Docker website: https://www.docker.com/products/docker-desktop
    • Docker Engine and Docker Compose (for Linux): On Linux, you can install Docker Engine and Docker Compose separately. Follow the instructions for your specific Linux distribution on the Docker website: https://docs.docker.com/get-docker/
  3. MongoDB Container Image:

    • You'll need access to the official MongoDB Docker image from Docker Hub. You can pull it using the following Docker command:
      docker pull mongo
      
  4. Text Editor or IDE:

    • You should have a code editor or an integrated development environment (IDE) installed for writing Node.js applications. Popular choices include Visual Studio Code, Sublime Text, and WebStorm.

The installation steps you provided seem to be for setting up a Node.js-based BookStore API with MongoDB as the database and Docker for containerization. Here's a breakdown of the steps:

Installation

  1. Clone the repo:

    Clone the project repository from GitHub using the git clone command:

    git clone https://github.com/Tam643/BookStoreAPI.git
  2. Create a .env file:

    Create a .env file in the project's root directory and set the following environment variables inside it:

    DB_URI=change_to_your_MongoDB_URI
    JWT_SECRET=change_to_your_secret

    You can manually create the .env file and add these variables, or you can create it using the Command Prompt:

    cd BookStoreAPI
    echo DB_URI=change_to_your_MongoDB_URI JWT_SECRET=change_to_your_secret > .env

    Replace change_to_your_MongoDB_URI with your actual MongoDB connection URI, and change_to_your_secret with your desired JWT secret key.

  3. Install NPM packages:

    Install the required Node.js packages using npm:

    npm install
  4. Start MongoDB:

    Make sure Docker Desktop is running, and then start a MongoDB container with the following command:

    docker run -d -p 0.0.0.0:27017:27017 --name mongodb mongo

    This command starts a MongoDB container and binds it to IP address 0.0.0.0 on port 27017.

  5. Start the application:

    Finally, start the BookStore API application:

    npm start

(back to top)

Usage

Getting Started

Now, the BookStore API is up and running locally on your machine. Before all should add a seed with the command

npm run seed

After the test you can clear up a database:

npm run clean

API Endpoints

The BookStore API provides the following endpoints:

  • List All Books:

    GET /books

    Retrieve a list of all books in the bookstore.

  • Get a Specific Book:

    GET /books/{id}

    Retrieve a specific book by its ID.

  • Create a New Book:

    POST /books

    Create a new book in the bookstore. Requires authentication.

  • Update a Book:

    PUT /books/{id}

    Update an existing book by its ID. Requires authentication.

  • Delete a Book:

    DELETE /books/{id}

    Delete a book by its ID. Requires authentication.

For more detailed information and examples, please refer to the API Documentation.

Authentication

The API uses JSON Web Tokens (JWT) for authentication. To access protected routes, include your JWT token in the Authorization header of your requests:

Authorization: Bearer your-access-token

Examples

Here are some examples of how to interact with the API:

  • List all books:

    curl http://localhost:3000/books
  • Get a specific book:

    curl http://localhost:3000/books/1

(back to top)

Contact

Project Link: https://github.com/Tam643/BookStoreAPI

(back to top)

Acknowledgments

wait a minute ....

(back to top)

About

Server-side REST API that serves requests from Frontend App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published