11 changed files with 6 additions and 140 deletions
@ -1,19 +0,0 @@ |
|||
from typing import Set, Union |
|||
|
|||
from fastapi import FastAPI, status |
|||
from pydantic import BaseModel |
|||
|
|||
app = FastAPI() |
|||
|
|||
|
|||
class Item(BaseModel): |
|||
name: str |
|||
description: Union[str, None] = None |
|||
price: float |
|||
tax: Union[float, None] = 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 |
|||
@ -1,29 +0,0 @@ |
|||
from typing import Set, 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: Set[str] = set() |
|||
|
|||
|
|||
@app.post("/items/", response_model=Item, tags=["items"]) |
|||
async def create_item(item: Item): |
|||
return item |
|||
|
|||
|
|||
@app.get("/items/", tags=["items"]) |
|||
async def read_items(): |
|||
return [{"name": "Foo", "price": 42}] |
|||
|
|||
|
|||
@app.get("/users/", tags=["users"]) |
|||
async def read_users(): |
|||
return [{"username": "johndoe"}] |
|||
@ -1,24 +0,0 @@ |
|||
from typing import Set, 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: Set[str] = set() |
|||
|
|||
|
|||
@app.post( |
|||
"/items/", |
|||
response_model=Item, |
|||
summary="Create an item", |
|||
description="Create an item with all the information, name, description, price, tax and a set of unique tags", |
|||
) |
|||
async def create_item(item: Item): |
|||
return item |
|||
@ -1,28 +0,0 @@ |
|||
from typing import Set, 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: Set[str] = set() |
|||
|
|||
|
|||
@app.post("/items/", response_model=Item, summary="Create an item") |
|||
async def create_item(item: Item): |
|||
""" |
|||
Create an item with all the information: |
|||
|
|||
- **name**: each item must have a name |
|||
- **description**: a long description |
|||
- **price**: required |
|||
- **tax**: if the item doesn't have tax, you can omit this |
|||
- **tags**: a set of unique tag strings for this item |
|||
""" |
|||
return item |
|||
@ -1,33 +0,0 @@ |
|||
from typing import Set, 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: Set[str] = set() |
|||
|
|||
|
|||
@app.post( |
|||
"/items/", |
|||
response_model=Item, |
|||
summary="Create an item", |
|||
response_description="The created item", |
|||
) |
|||
async def create_item(item: Item): |
|||
""" |
|||
Create an item with all the information: |
|||
|
|||
- **name**: each item must have a name |
|||
- **description**: a long description |
|||
- **price**: required |
|||
- **tax**: if the item doesn't have tax, you can omit this |
|||
- **tags**: a set of unique tag strings for this item |
|||
""" |
|||
return item |
|||
Loading…
Reference in new issue