mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-28 08:40:21 -05:00
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nils-Hero Lindemann <nilsherolindemann@proton.me>
27 lines
543 B
Python
27 lines
543 B
Python
from dataclasses import dataclass, field
|
|
from typing import Union
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
|
@dataclass
|
|
class Item:
|
|
name: str
|
|
price: float
|
|
tags: list[str] = field(default_factory=list)
|
|
description: Union[str, None] = None
|
|
tax: Union[float, None] = None
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/items/next", response_model=Item)
|
|
async def read_next_item():
|
|
return {
|
|
"name": "Island In The Moon",
|
|
"price": 12.99,
|
|
"description": "A place to be playin' and havin' fun",
|
|
"tags": ["breater"],
|
|
}
|