mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-05 15:45:19 -04:00
📝 Update docs, add first tutorials
This commit is contained in:
26
docs/tutorial/src/all/tutorial016.py
Normal file
26
docs/tutorial/src/all/tutorial016.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from fastapi import FastAPI, Path
|
||||
from pydantic import BaseModel
|
||||
|
||||
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 = Path(..., title="The ID of the item to get", ge=0, le=1000),
|
||||
q: str,
|
||||
item: Item = None,
|
||||
):
|
||||
results = {"item_id": item_id}
|
||||
if q:
|
||||
results.update({"q": q})
|
||||
if item:
|
||||
results.update({"item": item})
|
||||
return results
|
||||
Reference in New Issue
Block a user