docs_src/body_multiple_params/tutorial005_py310.py
raw| 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(item_id: int, item: Item = Body(embed=True)): |
| 16 | results = {"item_id": item_id, "item": item} |
| 17 | return results |