mirror of
https://github.com/rjNemo/fastapi
synced 2026-06-06 10:36:39 +00:00
26 lines
523 B
Python
26 lines
523 B
Python
from fastapi import FastAPI, Query, 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
|