mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-07 00:25:31 -04:00
📝 Add tutorials python src files
This commit is contained in:
29
docs/tutorial/src/tutorial34-02.py
Normal file
29
docs/tutorial/src/tutorial34-02.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from fastapi import Body, FastAPI
|
||||
from pydantic import BaseModel, Schema
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: str = None
|
||||
price: float
|
||||
tax: float = None
|
||||
|
||||
|
||||
@app.put("/items/{item_id}")
|
||||
async def update_item(
|
||||
*,
|
||||
item_id: int,
|
||||
item: Item = Body(
|
||||
...,
|
||||
example={
|
||||
"name": "Foo",
|
||||
"description": "A very nice Item",
|
||||
"price": 35.4,
|
||||
"tax": 3.2,
|
||||
},
|
||||
)
|
||||
):
|
||||
results = {"item_id": item_id, "item": item}
|
||||
return results
|
||||
Reference in New Issue
Block a user