| 1 |
from typing import Annotated |
| 2 |
|
| 3 |
from fastapi import Body, FastAPI |
| 4 |
from pydantic import BaseModel |
| 5 |
|
| 6 |
app = FastAPI() |
| 7 |
|
| 8 |
|
| 9 |
class Item(BaseModel): |
| 10 |
name: str |
| 11 |
description: str | None = None |
| 12 |
price: float |
| 13 |
tax: float | None = None |
| 14 |
|
| 15 |
|
| 16 |
class User(BaseModel): |
| 17 |
username: str |
| 18 |
full_name: str | None = None |
| 19 |
|
| 20 |
|
| 21 |
@app.put("/items/{item_id}") |
| 22 |
async def update_item( |
| 23 |
item_id: int, item: Item, user: User, importance: Annotated[int, Body()] |
| 24 |
): |
| 25 |
results = {"item_id": item_id, "item": item, "user": user, "importance": importance} |
| 26 |
return results |