docs/examples/onboarding/django/post_json.py
raw| 1 | from dataclasses import dataclass |
| 2 | |
| 3 | from litestar import Litestar, post |
| 4 | from litestar.params import JSONBody |
| 5 | |
| 6 | |
| 7 | @dataclass |
| 8 | class Item: |
| 9 | name: str |
| 10 | price: float |
| 11 | |
| 12 | |
| 13 | @post("/items") |
| 14 | async def create_item(data: JSONBody[Item]) -> Item: |
| 15 | return data |
| 16 | |
| 17 | |
| 18 | app = Litestar(route_handlers=[create_item]) |