mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-05 23:55:06 -04:00
📝 Update docs, add first tutorials
This commit is contained in:
33
docs/tutorial/src/all/tutorial029.py
Normal file
33
docs/tutorial/src/all/tutorial029.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from typing import List, Set
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
from pydantic.types import UrlStr
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Image(BaseModel):
|
||||
url: UrlStr
|
||||
name: str
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: str = None
|
||||
price: float
|
||||
tax: float = None
|
||||
tags: Set[str] = []
|
||||
image: List[Image] = None
|
||||
|
||||
|
||||
class Offer(BaseModel):
|
||||
name: str
|
||||
description: str = None
|
||||
price: float
|
||||
items: List[Item]
|
||||
|
||||
|
||||
@app.post("/offers/")
|
||||
async def create_offer(*, offer: Offer):
|
||||
return offer
|
||||
Reference in New Issue
Block a user