| 1 |
import pathlib |
| 2 |
|
| 3 |
from litestar import Litestar, get |
| 4 |
from litestar.params import FromPath |
| 5 |
|
| 6 |
|
| 7 |
@get("/user/{username:str}", sync_to_thread=False) |
| 8 |
def show_user_profile(username: FromPath[str]) -> str: |
| 9 |
return f"User {username}" |
| 10 |
|
| 11 |
|
| 12 |
@get("/post/{post_id:int}", sync_to_thread=False) |
| 13 |
def show_post(post_id: FromPath[int]) -> str: |
| 14 |
return f"Post {post_id}" |
| 15 |
|
| 16 |
|
| 17 |
@get("/path/{subpath:path}", sync_to_thread=False) |
| 18 |
def show_subpath(subpath: FromPath[pathlib.Path]) -> str: |
| 19 |
return f"Subpath {subpath}" |
| 20 |
|
| 21 |
|
| 22 |
app = Litestar(route_handlers=[show_user_profile, show_post, show_subpath]) |