mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-30 09:39:20 -05:00
20 lines
398 B
Python
20 lines
398 B
Python
from typing import Optional
|
|
|
|
from fastapi import FastAPI, status
|
|
from pydantic import BaseModel
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: Optional[str] = None
|
|
price: float
|
|
tax: Optional[float] = None
|
|
tags: set[str] = set()
|
|
|
|
|
|
@app.post("/items/", response_model=Item, status_code=status.HTTP_201_CREATED)
|
|
async def create_item(item: Item):
|
|
return item
|