| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from dataclasses import dataclass |
| 4 |
|
| 5 |
from litestar import Litestar, post |
| 6 |
from litestar.dto import DataclassDTO, DTOConfig |
| 7 |
|
| 8 |
|
| 9 |
@dataclass |
| 10 |
class Person: |
| 11 |
name: str |
| 12 |
age: int |
| 13 |
email: str |
| 14 |
|
| 15 |
|
| 16 |
class ReadDTO(DataclassDTO[Person]): |
| 17 |
config = DTOConfig(exclude={"email"}) |
| 18 |
|
| 19 |
|
| 20 |
@post("/person", return_dto=ReadDTO, sync_to_thread=False) |
| 21 |
def create_person(data: Person) -> Person: |
| 22 |
# Logic for persisting the person goes here |
| 23 |
return data |
| 24 |
|
| 25 |
|
| 26 |
app = Litestar(route_handlers=[create_person]) |