Block 66: FastAPI: Modern API Design
Build a type-safe, auto-documented API with FastAPI.
Concepts
- pip install fastapi uvicorn
- @app.get(), @app.post() decorators
- Path parameters and query parameters with type hints
- Automatic docs at /docs (Swagger UI)
Code Examples
See exercise below.
Exercise
Create a FastAPI app with 3 routes: /, /items/{item_id}, /search?q=term. Test in /docs. Add a query parameter with a default value and an optional description.
Homework
Compare Flask and FastAPI: what are the 3 biggest differences for a beginner building an API? Thursday