Debian Codegraph @

docs/examples/onboarding/fastapi/lifespan.py

raw
1 from collections.abc import AsyncIterator
2 from contextlib import asynccontextmanager
3
4 from litestar import Litestar, get
5
6
7 @asynccontextmanager
8 async def lifespan(app: Litestar) -> AsyncIterator[None]:
9 # Setup code runs before the application starts accepting requests.
10 yield
11 # Teardown code runs after the application has stopped.
12
13
14 @get("/")
15 async def index() -> dict[str, str]:
16 return {"hello": "world"}
17
18
19 app = Litestar(route_handlers=[index], lifespan=[lifespan])