mirror of https://github.com/tiangolo/fastapi.git
27 lines
486 B
Python
27 lines
486 B
Python
from fastapi import FastAPI
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: str | None = None
|
|
|
|
|
|
app = FastAPI(separate_input_output_schemas=False)
|
|
|
|
|
|
@app.post("/items/")
|
|
def create_item(item: Item):
|
|
return item
|
|
|
|
|
|
@app.get("/items/")
|
|
def read_items() -> list[Item]:
|
|
return [
|
|
Item(
|
|
name="Portal Gun",
|
|
description="Device to travel through the multi-rick-verse",
|
|
),
|
|
Item(name="Plumbus"),
|
|
]
|