| 1 |
from fastapi import Body, FastAPI |
| 2 |
from pydantic import BaseModel |
| 3 |
|
| 4 |
app = FastAPI() |
| 5 |
|
| 6 |
|
| 7 |
class Item(BaseModel): |
| 8 |
name: str |
| 9 |
description: str | None = None |
| 10 |
price: float |
| 11 |
tax: float | None = None |
| 12 |
|
| 13 |
|
| 14 |
@app.put("/items/{item_id}") |
| 15 |
async def update_item( |
| 16 |
item_id: int, |
| 17 |
item: Item = Body( |
| 18 |
examples=[ |
| 19 |
{ |
| 20 |
"name": "Foo", |
| 21 |
"description": "A very nice Item", |
| 22 |
"price": 35.4, |
| 23 |
"tax": 3.2, |
| 24 |
} |
| 25 |
], |
| 26 |
), |
| 27 |
): |
| 28 |
results = {"item_id": item_id, "item": item} |
| 29 |
return results |