2023-01-07 15:45:48 +02:00
|
|
|
from typing import Any, List, Union
|
2018-12-14 21:35:19 +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-14 21:35:19 +04:00
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Item(BaseModel):
|
|
|
|
|
name: str
|
2022-05-14 06:59:59 -05:00
|
|
|
description: Union[str, None] = None
|
2018-12-14 21:35:19 +04:00
|
|
|
price: float
|
2022-05-14 06:59:59 -05:00
|
|
|
tax: Union[float, None] = None
|
2019-05-25 11:35:57 -04:00
|
|
|
tags: List[str] = []
|
2018-12-14 21:35:19 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/items/", response_model=Item)
|
2023-01-07 15:45:48 +02:00
|
|
|
async def create_item(item: Item) -> Any:
|
2018-12-14 21:35:19 +04:00
|
|
|
return item
|
2023-01-07 15:45:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/items/", response_model=List[Item])
|
|
|
|
|
async def read_items() -> Any:
|
|
|
|
|
return [
|
|
|
|
|
{"name": "Portal Gun", "price": 42.0},
|
|
|
|
|
{"name": "Plumbus", "price": 32.0},
|
|
|
|
|
]
|