mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-04 07:12:48 -04:00
📝 Add first tutorial src files
This commit is contained in:
29
docs/tutorial/src/tutorial35.py
Normal file
29
docs/tutorial/src/tutorial35.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from fastapi import Body, FastAPI, Path, Query
|
||||
from pydantic import BaseModel
|
||||
from typing import Set
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Image(BaseModel):
|
||||
url: str
|
||||
name: str
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: str = None
|
||||
price: float
|
||||
tax: float = None
|
||||
tags: Set[str] = []
|
||||
image: Image = None
|
||||
|
||||
|
||||
@app.put("/items/{item_id}")
|
||||
async def update_item(
|
||||
*,
|
||||
item_id: int,
|
||||
item: Item,
|
||||
):
|
||||
results = {"item_id": item_id, "item": item}
|
||||
return results
|
||||
Reference in New Issue
Block a user