2022-05-14 06:59:59 -05:00
|
|
|
from typing import Set, Union
|
2018-12-15 14:39:11 +04:00
|
|
|
|
2018-12-18 21:59:06 +04:00
|
|
|
from fastapi import FastAPI
|
2018-12-18 22:36:04 +04:00
|
|
|
from pydantic import BaseModel
|
2018-12-18 21:59:06 +04:00
|
|
|
|
2018-12-15 14:39:11 +04:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
name: str
|
2022-05-14 06:59:59 -05:00
|
|
|
description: Union[str, None] = None
|
2018-12-15 14:39:11 +04:00
|
|
|
price: float
|
2022-05-14 06:59:59 -05:00
|
|
|
tax: Union[float, None] = None
|
2022-01-07 15:11:31 +01:00
|
|
|
tags: Set[str] = set()
|
2018-12-15 14:39:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/items/", response_model=Item, tags=["items"])
|
2020-06-13 01:11:44 +05:30
|
|
|
async def create_item(item: Item):
|
2018-12-15 14:39:11 +04:00
|
|
|
return item
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/items/", tags=["items"])
|
|
|
|
|
async def read_items():
|
|
|
|
|
return [{"name": "Foo", "price": 42}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/users/", tags=["users"])
|
|
|
|
|
async def read_users():
|
|
|
|
|
return [{"username": "johndoe"}]
|