mirror of
https://github.com/fastapi/fastapi.git
synced 2026-11-21 10:13:53 +08:00
28 lines
579 B
Python
28 lines
579 B
Python
from typing import Annotated
|
|
|
|
from fastapi import FastAPI, Path
|
|
from pydantic import BaseModel
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: str | None = None
|
|
price: float
|
|
tax: float | None = None
|
|
|
|
|
|
@app.put("/items/{item_id}")
|
|
async def update_item(
|
|
item_id: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)],
|
|
q: str | None = None,
|
|
item: Item | None = None,
|
|
):
|
|
results = {"item_id": item_id}
|
|
if q:
|
|
results.update({"q": q})
|
|
if item:
|
|
results.update({"item": item})
|
|
return results
|