A simple FastAPI application for managing products.
This API supports CRUD operations (Create, Read, Update, Delete) with in-memory storage using Python dictionaries.
- Create a product ✅
- Retrieve all products ✅
- Retrieve a single product by ID ✅
- Update an existing product ✅
- Delete a product ✅
- Automatic 400 Bad Request and 404 Not Found error handling
- Returns 204 No Content on successful deletion
git clone https://github.com/your-username/fastapi-products-api.git
cd fastapi-products-apipython -m venv venv
source venv/bin/activate # On Linux/Mac
venv\Scripts\activate # On Windowspip install -r requirements.txtStart the FastAPI server with Uvicorn:
uvicorn server:app --reload- The app will run at: http://127.0.0.1:8000
- Open the interactive API docs at: http://127.0.0.1:8000/docs
POST /products
{
"name": "Laptop",
"description": "A powerful gaming laptop",
"price": 1500
}Responses:
200 OK→ Returns the created product400 Bad Request→ Missing name or invalid price
GET /products
{
"7d89f09a-9f7a-4c3c-bb9d-d731a5bfae1d": {
"id": "7d89f09a-9f7a-4c3c-bb9d-d731a5bfae1d",
"name": "Laptop",
"description": "A powerful gaming laptop",
"price": 1500,
"created_at": "2025-08-19T10:30:00",
"updated_at": "2025-08-19T10:30:00"
}
}GET /products/{id}
Responses:
200 OK→ Returns the product404 Not Found→ Product does not exist
PUT /products/{id}
{
"name": "Updated Laptop",
"price": 1400
}Responses:
200 OK→ Returns the updated product404 Not Found→ Product not found
DELETE /products/{id}
Responses:
204 No Content→ Successfully deleted404 Not Found→ Product not found
- Python 3.10
- FastAPI — Web framework
- Uvicorn — ASGI server
- Dataclasses — To manage product data
This project is licensed under the MIT License. You’re free to use, modify, and distribute it.