Building APIs with FastAPI · 12-day planAll days
Day 11 of 12 30 minMiddlewareCORSasync
Add behaviour around every request with middleware - timing, request IDs and logging - and let browser apps on other domains call your API with CORS. Run work after the response with background tasks, and learn when to write async def, when plain def is better, and why it matters.
By the end of today you can
- Write HTTP middleware that runs before and after every request
- Configure CORS so a website on another domain can call the API
- Run follow-up work with BackgroundTasks after responding
- Choose between def and async def for endpoints
- Avoid blocking the event loop in async code
What's inside
- 4 sections
- 4 diagrams and mind maps
- 3 code examples you can run
- 5-question quiz
- 1Middleware
- 2CORS: letting browser apps call you
- 3Background tasks
- 4def or async def?
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free