4 changed files with 82 additions and 7 deletions
@ -0,0 +1,28 @@ |
|||
from fastapi import FastAPI |
|||
from pydantic import BaseModel |
|||
|
|||
app = FastAPI() |
|||
|
|||
|
|||
class Item(BaseModel): |
|||
name: str |
|||
description: str | None = None |
|||
price: float |
|||
tax: 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 |
|||
\f |
|||
:param item: User input. |
|||
""" |
|||
return item |
|||
@ -0,0 +1,30 @@ |
|||
from typing import 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 |
|||
\f |
|||
:param item: User input. |
|||
""" |
|||
return item |
|||
Loading…
Reference in new issue