2022-05-14 06:59:59 -05:00
|
|
|
from typing import Union
|
2022-01-07 15:11:31 +01:00
|
|
|
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
name: str
|
2022-05-14 06:59:59 -05:00
|
|
|
description: Union[str, None] = None
|
2022-01-07 15:11:31 +01: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()
|
|
|
|
|
|
|
|
|
|
|
2026-02-04 15:07:26 +03:00
|
|
|
@app.post("/items/", tags=["items"])
|
|
|
|
|
async def create_item(item: Item) -> Item:
|
2022-01-07 15:11:31 +01: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"}]
|