Debian Codegraph @

docs/examples/onboarding/django/routers.py

raw
1 from litestar import Litestar, Router, get
2 from litestar.params import FromPath
3
4
5 @get("/")
6 async def list_items() -> list[dict[str, int]]:
7 return [{"id": 1}]
8
9
10 @get("/{item_id:int}")
11 async def get_item(item_id: FromPath[int]) -> dict[str, int]:
12 return {"id": item_id}
13
14
15 items_router = Router(path="/items", route_handlers=[list_items, get_item])
16 api_router = Router(path="/api/v1", route_handlers=[items_router])
17
18 app = Litestar(route_handlers=[api_router])