updated example

This commit is contained in:
Nancy Wang 2025-11-25 17:40:13 +00:00
parent 372049d60d
commit 66bc00ca83
1 changed files with 12 additions and 0 deletions

12
main.py
View File

@ -1,10 +1,17 @@
from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
is_offer: Union[bool, None] = None
@app.get("/")
def read_root():
return {"Hello": "World"}
@ -13,3 +20,8 @@ def read_root():
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
@app.put("/items/{item_id}")
def update_item(item_id: int, item: Item):
return {"item_name": item.name, "item_id": item_id}