docs/examples/onboarding/flask/serialization.py
raw| 1 | from litestar import Litestar, MediaType, get |
| 2 | |
| 3 | |
| 4 | @get("/json", sync_to_thread=False) |
| 5 | def get_json() -> dict[str, str]: |
| 6 | return {"hello": "world"} |
| 7 | |
| 8 | |
| 9 | @get("/text", media_type=MediaType.TEXT, sync_to_thread=False) |
| 10 | def get_text() -> str: |
| 11 | return "hello, world" |
| 12 | |
| 13 | |
| 14 | @get("/html", media_type=MediaType.HTML, sync_to_thread=False) |
| 15 | def get_html() -> str: |
| 16 | return "<strong>hello, world</strong>" |
| 17 | |
| 18 | |
| 19 | app = Litestar(route_handlers=[get_json, get_text, get_html]) |