This is the backend API for an e-commerce website built using FastAPI and MongoDB. It provides endpoints for managing products and orders.
- List available products
- Create new orders
- Fetch orders with pagination
- Fetch a specific order by ID
- Update product quantities
These instructions will help you set up and run the FastAPI backend on your local machine for development and testing purposes.
- Python 3.8+
- MongoDB (You can use MongoDB Atlas for cloud-hosted MongoDB)
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
- 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.
- 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" }
}
- Endpoint: GET /orders/?limit=2&offset=2
- Description: Retrieves a list of all orders with optional pagination.
- Endpoint: GET /orders/{order_id}
- Description: Retrieves a specific order by its ID.