Skip to content

About

this is just a training project

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛍️ FastAPI Products API

A simple FastAPI application for managing products.
This API supports CRUD operations (Create, Read, Update, Delete) with in-memory storage using Python dictionaries.


🚀 Features

  • 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

📦 Installation

1️⃣ Clone the repository

git clone https://github.com/your-username/fastapi-products-api.git
cd fastapi-products-api

2️⃣ Create and activate a virtual environment (optional but recommended)

python -m venv venv
source venv/bin/activate    # On Linux/Mac
venv\Scripts\activate       # On Windows

3️⃣ Install dependencies

pip install -r requirements.txt

▶️ Running the Application

Start the FastAPI server with Uvicorn:

uvicorn server:app --reload

📌 API Endpoints

1. Create a product

POST /products

{
  "name": "Laptop",
  "description": "A powerful gaming laptop",
  "price": 1500
}

Responses:

  • 200 OK → Returns the created product
  • 400 Bad Request → Missing name or invalid price

2. Get all products

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"
  }
}

3. Get product by ID

GET /products/{id} Responses:

  • 200 OK → Returns the product
  • 404 Not Found → Product does not exist

4. Update product

PUT /products/{id}

{
  "name": "Updated Laptop",
  "price": 1400
}

Responses:

  • 200 OK → Returns the updated product
  • 404 Not Found → Product not found

5. Delete product

DELETE /products/{id} Responses:

  • 204 No Content → Successfully deleted
  • 404 Not Found → Product not found

🛠️ Technologies Used

  • Python 3.10
  • FastAPI — Web framework
  • Uvicorn — ASGI server
  • Dataclasses — To manage product data

📄 License

This project is licensed under the MIT License. You’re free to use, modify, and distribute it.


About

this is just a training project

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages