docs/examples/responses/custom_responses.py
raw| 1 | from litestar import Litestar, Response, get |
| 2 | from litestar.datastructures import MultiDict |
| 3 | |
| 4 | |
| 5 | class MultiDictResponse(Response): |
| 6 | type_encoders = {MultiDict: lambda d: d.dict()} |
| 7 | |
| 8 | |
| 9 | @get("/") |
| 10 | async def index() -> MultiDict: |
| 11 | return MultiDict([("foo", "bar"), ("foo", "baz")]) |
| 12 | |
| 13 | |
| 14 | app = Litestar([index], response_class=MultiDictResponse) |
| 15 | |
| 16 | |
| 17 | # run: / |