A progressive tutorial for learning FastAPI, where each example builds upon the previous one.
- Python 3.11 or higher
- Basic understanding of Python
- Familiarity with REST APIs (helpful but not required)
This project uses uv as the package manager.
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"# Create a new directory
mkdir fastapi-tutorial
cd fastapi-tutorial
# Initialize with uv
uv init
# Add FastAPI and uvicorn
uv add fastapi uvicorn[standard]Each example can be run with:
uv run uvicorn example_XX:app --reloadThen visit http://localhost:8000 in your browser.
- Example 01: Hello World - Your first FastAPI application
- Example 02: Path Parameters - Dynamic routes
- Example 03: Query Parameters - URL parameters
- Example 04: Request Body - Handling POST requests with Pydantic
- Example 05: Response Models - Structured responses
- Example 06: Status Codes - HTTP status codes
- Example 07: Path Operations - Multiple HTTP methods
- Example 08: Dependencies - Dependency injection
- Example 09: Error Handling - Custom exception handlers
- Example 10: Complete CRUD API - A todo list application
Follow the examples in order. Each example includes:
- Python code file (
example_XX.py) - Explanation document (
example_XX.md) - Key concepts demonstrated
- What's new compared to the previous example
FastAPI automatically generates interactive API documentation:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc