A simple FastAPI application for learning API development with Python.
- Python 3.11+
- FastAPI
- Pydantic
- Uvicorn
# Install dependencies using uv
uv sync
# Or using pip
pip install fastapi[standard] pydantic uvicornuvicorn app:app --reloadThe API will be available at http://127.0.0.1:8000
GET /shy
Returns a greeting message.
GET /user/{user_id}
Path parameter example with type conversion.
GET /search?q={query}&page={page}&limit={limit}
Query parameters example with defaults (page=1, limit=10).
Example:
curl "http://127.0.0.1:8000/search?q=fastapi&page=2&limit=5"POST /users
Request body validation with Pydantic.
Example:
curl -X POST "http://127.0.0.1:8000/users" \
-H "Content-Type: application/json" \
-d '{"name": "Shylesh", "email": "shylesh@example.com", "age": 25}'POST /products
Field validation with constraints (name: 2-50 chars, price > 0, stock >= 0).
Example:
curl -X POST "http://127.0.0.1:8000/products" \
-H "Content-Type: application/json" \
-d '{"name": "Product1", "price": 100.0, "stock": 10}'POST /items
Returns 201 Created status code.
GET /users/db/{user_id}
Demonstrates HTTPException for error handling (returns 404 if user not found).
Example:
curl "http://127.0.0.1:8000/users/db/1"- Swagger UI:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc