Applies when building or reviewing Starlette applications. Covers middleware, lifespan events, streaming, WebSockets, and background tasks.
Request.state to pass data between middleware and handlers.BackgroundTask for fire-and-forget after response. Runs after response completes. For concurrent work, use a task queue.StreamingResponse for large payloads. Async generator avoids loading everything into memory.with TestClient(app) as client: fires lifespan events.is_disconnected() periodically.allow_origins=["*"] with allow_credentials=True. Forbidden by CORS spec.