GithubHelp home page GithubHelp logo

fastapi_mongodb's Introduction

E-commerce-API-App Using FAST API

This is an e-commerce application built with Python and FastAPI.

Overview

It provides various APIs for managing products, creating orders, and retrieving order information. The application utilizes a MongoDB database to store product and order data.

MongoDB Database

The application uses a MongoDB database to store product and order data. Make sure you have MongoDB installed and running on your system. Update the database connection details in the .env file.

Installation

  1. Clone the repository:
https://github.com/goodchai0/FastApi_MongoDb
  1. Navigate to the project directory:
cd FastApi_MongoDb
  1. Install the required dependencies:
pip install -r requirements.txt
  1. Ensure that MongoDB is installed and running on your system.
  2. Create a MongoDB database for the application and update the database connection details in the .env file.

Usage

  1. Start the FastAPI server:
python -m uvicorn main:app --reload
  1. Access the API endpoints in your preferred API testing tool or web browser.

APIs

The following APIs are available in the E-commerce Application:

You may use http://127.0.0.1:8000/docs#/ for swagger UI

Get All Products

  • Endpoint: api/products
  • Method: GET
  • Description: Retrieve all products from the db.
  • Response:
  • Status: 200 OK
  • Body: List of products.
[
    {
        "id": 1,
        "name": "TV",
        "price": 500.0,
        "available_quantity": 10,
        "category": "Electronics"
    },
    {
        "id": 2,
        "name": "Laptop",
        "price": 1000.0,
        "available_quantity": 5,
        "category": "Electronics"
    }
]

Create a New Order


Endpoint: api/orders
Method: POST
Example Request:

POST http://localhost:8000/api/orders
Content-Type: application/json

{
  "timestamp": "2023-07-08T10:30:00",
  "items": [
    {
      "productId": "1",
      "boughtQuantity": 2
    },
    {
      "productId": "2",
      "boughtQuantity": 1
    }
  ],
  "totalAmount": 0.0,
  "userAddress": {
    "city": "Sample City",
    "country": "Sample Country",
    "zipCode": "12345"
  }
}

Get All Orders


Endpoint: api/orders
Method: GET
Example Request:

[
    {
        "timestamp": "2023-07-09T15:27:14.092011",
        "items": [
            {
                "productId": 1,
                "boughtQuantity": 2
            },
            {
                "productId": 2,
                "boughtQuantity": 1
            }
        ],
        "totalAmount": 1.0,
        "userAddress": {
            "city": "Sample City",
            "country": "Sample Country",
            "zipCode": "12345"
        }
    },
    {
        "timestamp": "2023-07-09T15:29:28.591415",
        "items": [
            {
                "productId": 1,
                "boughtQuantity": 2
            },
            {
                "productId": 2,
                "boughtQuantity": 1
            }
        ],
        "totalAmount": 3499.9700000000003,
        "userAddress": {
            "city": "Sample City",
            "country": "Sample Country",
            "zipCode": "12345"
        }
    }]

Get Single Orders


Endpoint: api/orders/<id>
Method: GET

Update Product


Endpoint: api/products/<product_id:int>
Method: GET
Example Request:

PUT http://localhost:8000/api/products/1
Content-Type: application/json

{
    "id": 1,
    "name": "TV",
    "price": 999.99,
    "available_quantity": 20,
    "category": "Electronics"
}

fastapi_mongodb's People

Contributors

goodchai0 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.