generated from litestar-org/litestar-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
38 lines (25 loc) · 984 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Minimal Litestar application."""
from __future__ import annotations
from asyncio import sleep
from typing import Any, Dict
from litestar import Litestar, Request, get
__all__ = ("async_hello_world", "sync_hello_world")
@get("/async")
async def async_hello_world() -> Dict[str, Any]: # noqa: UP006
"""Route Handler that outputs hello world."""
await sleep(0.1)
return {"hello": "world"}
@get("/sync", sync_to_thread=False)
def sync_hello_world() -> Dict[str, Any]: # noqa: UP006
"""Route Handler that outputs hello world."""
return {"hello": "world"}
def before_request_handler_works(request: Request) -> None:
"""Before Request Handler."""
print("Before Request Handler")
def before_request_handler_doesnt_work(request: Request) -> Any:
"""Before Request Handler."""
print("Before Request Handler")
app = Litestar(
route_handlers=[sync_hello_world, async_hello_world],
before_request=before_request_handler_doesnt_work,
)