Giter Site home page Giter Site logo

akshayrcc / bookstore Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 11 KB

In this project, we have created an online bookstore API that allows users to view, search, and purchase books. The API is built using FastAPI and the book data is stored in MongoDB.

License: MIT License

Python 100.00%

bookstore's Introduction

Online Bookstore API

A bookstore-fast-API

This project is an online bookstore API built using FastAPI and MongoDB. It allows users to view, search, and purchase books. The API includes various features such as data validation, aggregation, indexing, search functionality, and asynchronous programming.

Team Members

[Akshay Chaudhari]
[Sambhaji Ippar]

Prerequisites

Python 3.8 or higher
MongoDB
FastAPI
PyMongo

Installation

Clone the GitHub repository:
git clone https://github.com/your-username/bookstore-api.git

Change to the project directory:
cd bookstore-api

Install the required dependencies:
pip install -r requirements.txt

Configure the MongoDB connection settings in api_constants.py.

Commands for virtual environment

python3 -m venv venv --system-site-packages
source venv/bin/activate
deactivate

Usage

Start the API server:
python3 -m uvicorn main:app --port 8090 --reload  

Access the API documentation in your browser at http://localhost:8090/docs.

API Endpoints

GET /books

Retrieves a list of all books in the store.

GET /books/{book_id}

Retrieves a specific book by ID.

POST /books

Adds a new book to the store.

PUT /books/{book_id}

Updates an existing book by ID.

DELETE /books/{book_id}

Deletes a book from the store by ID.

GET /search?title={}&author={}&min_price={}&max_price={}

Searches for books by title, author, and price range.

Data Model

The book data model includes the following fields:

title (string): The title of the book.
author (string): The author of the book.
description (string): A description of the book.
price (float): The price of the book.
stock (integer): The available stock of the book.

MongoDB Connection

The API establishes an asynchronous connection to MongoDB using PyMongo.
Data Validation

Pydantic is used to validate the incoming book data before it is stored in MongoDB. 
The API returns an appropriate error message if the data fails validation.

Aggregation

The API uses MongoDB's aggregation framework to retrieve the following data:

The total number of books in the store.
The top 5 bestselling books.
The top 5 authors with the most books in the store.

Indexing

Appropriate indexes are created for the MongoDB collection to optimize query performance.
Operators

MongoDB's query operators are used to implement the following search functionality:

Search for books by title.
Search for books by author.
Search for books by price range.

Asynchronous Programming

All database operations are done asynchronously to ensure the API remains responsive and performant.

bookstore's People

Contributors

akshayrcc avatar

Watchers

Kostas Georgiou 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.