mirror of https://github.com/tiangolo/fastapi.git
20 lines
517 B
Python
20 lines
517 B
Python
from typing import Union
|
|
|
|
from fastapi import FastAPI
|
|
from pydantic import BaseModel, Field
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str = Field(examples=["Foo"])
|
|
description: Union[str, None] = Field(default=None, examples=["A very nice Item"])
|
|
price: float = Field(examples=[35.4])
|
|
tax: Union[float, None] = Field(default=None, examples=[3.2])
|
|
|
|
|
|
@app.put("/items/{item_id}")
|
|
async def update_item(item_id: int, item: Item):
|
|
results = {"item_id": item_id, "item": item}
|
|
return results
|