mirror of https://github.com/tiangolo/fastapi.git
20 lines
388 B
Python
20 lines
388 B
Python
from typing import Union
|
|
|
|
from fastapi import FastAPI, status
|
|
from pydantic import BaseModel
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: Union[str, None] = None
|
|
price: float
|
|
tax: Union[float, None] = None
|
|
tags: set[str] = set()
|
|
|
|
|
|
@app.post("/items/", status_code=status.HTTP_201_CREATED)
|
|
async def create_item(item: Item) -> Item:
|
|
return item
|