4 changed files with 73 additions and 5 deletions
@ -0,0 +1,25 @@ |
|||||
|
from dataclasses import dataclass, field |
||||
|
|
||||
|
from fastapi import FastAPI |
||||
|
|
||||
|
|
||||
|
@dataclass |
||||
|
class Item: |
||||
|
name: str |
||||
|
price: float |
||||
|
tags: list[str] = field(default_factory=list) |
||||
|
description: str | None = None |
||||
|
tax: 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"], |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
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"], |
||||
|
} |
||||
Loading…
Reference in new issue