Welcome to my FastAPI playground where I took my first spin with FastAPI and went from uvicorn
confusion to full-blown route domination.
This repo contains my hands-on experiments and learnings from the world of FastAPI. Hereβs a breakdown of my FastAPI road trip:
- Created and activated a virtual environment using
venv
- Installed required dependencies:
pip install fastapi uvicorn
Ran the server using:
Copy
Edit
uvicorn main:app --reload
Concept Description:
-> FastAPI() Initializing the app -> @app.get, .post Declaring API routes -> BaseModel class Pydantic models for data validation -> Path and Query Handling path & query parameters -> Swagger UI Auto-generated docs at /docs -> ReDoc Alternative docs at /redoc
1.) GET / β Welcome route
2.) GET /get-items/{item_id} β Path param demo
3.) GET /get-by-name?name=Milk β Query param demo
4.) POST /create-item/{item_id} β Create new item via body
5.) PUT /update-item/{item_id} β Update item data
6.) DELETE /delete-item/{item_id} β Delete an item
Visit: http://127.0.0.1:8000/docs
-> Interactive UI for testing all endpoints -> Model validation + auto schema generation
π¦ Sample Data Used python
Copy
Edit
inventory = {
1: {"name": "Milk", "price": 3.99, "brand": "Regular"}
}
MSIT = {
1: {"Name": "Nevin Bali", "SGPA": 9.847}
}