gjboxer / fastapi-python-backend

A FastAPI python backend for an Ecommerce Website

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FastAPI E-commerce Backend

This is the backend API for an e-commerce website built using FastAPI and MongoDB. It provides endpoints for managing products and orders.

Features

  • List available products
  • Create new orders
  • Fetch orders with pagination
  • Fetch a specific order by ID
  • Update product quantities

Getting Started

These instructions will help you set up and run the FastAPI backend on your local machine for development and testing purposes.

Prerequisites

  • Python 3.8+
  • MongoDB (You can use MongoDB Atlas for cloud-hosted MongoDB)

Installation

git clone https://github.com/gjboxer/fastapi-python-backend
pip install -r requirements.txt
py testmdb.py

-Backend will get started at http://127.0.0.1:8000

API Endpoints

  • GET /products/: List all available products.
  • POST /orders/: Create a new order.
  • GET /orders/: Fetch all orders with pagination.
  • GET /orders/{order_id}: Fetch a specific order by ID.
  • PUT /products/{product_id}/update_quantity/: Update the available quantity for a product by ID.

Here's a usage guide for the API endpoints with examples:

List All Available Products

  • Endpoint: GET /products/
  • Description: Retrieves a list of all available products. Screenshot 2023-09-23 025119

Create a New Order

  • Endpoint: POST /orders/
  • Description: Creates a new order with selected products and quantities.
  • json body
    {
      "items": [
            {
        "productId": "650dd22da15d0fa4b37eec2c",
        "boughtQuantity": 1
      }
      ],
      "total_amount": 0.0,
      "user_address": {
          "city": "City",
          "country": "Country",
          "zip_code": "12243236"
      }

}

Screenshot 2023-09-23 025825

Fetch All Orders with Pagination

  • Endpoint: GET /orders/?limit=2&offset=2
  • Description: Retrieves a list of all orders with optional pagination.

image

Fetch a Specific Order by ID

  • Endpoint: GET /orders/{order_id}
  • Description: Retrieves a specific order by its ID.

image

Update Product Quantity

  • Endpoint: PUT /products/{product_id}/update_quantity/?new_quantity=100
  • Description: Update the available quantity of a product by providing its unique product ID. image

About

A FastAPI python backend for an Ecommerce Website


Languages

Language:Python 100.0%