| 1 |
from dataclasses import dataclass, field |
| 2 |
|
| 3 |
from fastapi import FastAPI |
| 4 |
|
| 5 |
|
| 6 |
@dataclass |
| 7 |
class Item: |
| 8 |
name: str |
| 9 |
price: float |
| 10 |
tags: list[str] = field(default_factory=list) |
| 11 |
description: str | None = None |
| 12 |
tax: float | None = None |
| 13 |
|
| 14 |
|
| 15 |
app = FastAPI() |
| 16 |
|
| 17 |
|
| 18 |
@app.get("/items/next", response_model=Item) |
| 19 |
async def read_next_item(): |
| 20 |
return { |
| 21 |
"name": "Island In The Moon", |
| 22 |
"price": 12.99, |
| 23 |
"description": "A place to be playin' and havin' fun", |
| 24 |
"tags": ["breater"], |
| 25 |
} |