22 changed files with 12 additions and 93 deletions
@ -1,27 +0,0 @@ |
|||||
from typing import Any, List, Union |
|
||||
|
|
||||
from fastapi import FastAPI |
|
||||
from pydantic import BaseModel |
|
||||
|
|
||||
app = FastAPI() |
|
||||
|
|
||||
|
|
||||
class Item(BaseModel): |
|
||||
name: str |
|
||||
description: Union[str, None] = None |
|
||||
price: float |
|
||||
tax: Union[float, None] = None |
|
||||
tags: List[str] = [] |
|
||||
|
|
||||
|
|
||||
@app.post("/items/", response_model=Item) |
|
||||
async def create_item(item: Item) -> Any: |
|
||||
return item |
|
||||
|
|
||||
|
|
||||
@app.get("/items/", response_model=List[Item]) |
|
||||
async def read_items() -> Any: |
|
||||
return [ |
|
||||
{"name": "Portal Gun", "price": 42.0}, |
|
||||
{"name": "Plumbus", "price": 32.0}, |
|
||||
] |
|
||||
@ -1,27 +0,0 @@ |
|||||
from typing import List, Union |
|
||||
|
|
||||
from fastapi import FastAPI |
|
||||
from pydantic import BaseModel |
|
||||
|
|
||||
app = FastAPI() |
|
||||
|
|
||||
|
|
||||
class Item(BaseModel): |
|
||||
name: str |
|
||||
description: Union[str, None] = None |
|
||||
price: float |
|
||||
tax: Union[float, None] = None |
|
||||
tags: List[str] = [] |
|
||||
|
|
||||
|
|
||||
@app.post("/items/") |
|
||||
async def create_item(item: Item) -> Item: |
|
||||
return item |
|
||||
|
|
||||
|
|
||||
@app.get("/items/") |
|
||||
async def read_items() -> List[Item]: |
|
||||
return [ |
|
||||
Item(name="Portal Gun", price=42.0), |
|
||||
Item(name="Plumbus", price=32.0), |
|
||||
] |
|
||||
@ -1,26 +0,0 @@ |
|||||
from typing import List, Union |
|
||||
|
|
||||
from fastapi import FastAPI |
|
||||
from pydantic import BaseModel |
|
||||
|
|
||||
app = FastAPI() |
|
||||
|
|
||||
|
|
||||
class Item(BaseModel): |
|
||||
name: str |
|
||||
description: Union[str, None] = None |
|
||||
price: float |
|
||||
tax: float = 10.5 |
|
||||
tags: List[str] = [] |
|
||||
|
|
||||
|
|
||||
items = { |
|
||||
"foo": {"name": "Foo", "price": 50.2}, |
|
||||
"bar": {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2}, |
|
||||
"baz": {"name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": []}, |
|
||||
} |
|
||||
|
|
||||
|
|
||||
@app.get("/items/{item_id}", response_model=Item, response_model_exclude_unset=True) |
|
||||
async def read_item(item_id: str): |
|
||||
return items[item_id] |
|
||||
Loading…
Reference in new issue