Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,12 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.responses import HTMLResponse
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
app = FastAPI()
|
| 5 |
|
| 6 |
|
|
@@ -14,7 +20,6 @@ def home():
|
|
| 14 |
def hello():
|
| 15 |
return {"hello": "world"}
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
return {"greeting": f"Hello {name}!"}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
|
| 5 |
+
class Item(BaseModel):
|
| 6 |
+
name: str
|
| 7 |
+
price: float
|
| 8 |
+
|
| 9 |
+
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
|
|
|
|
| 20 |
def hello():
|
| 21 |
return {"hello": "world"}
|
| 22 |
|
| 23 |
+
@app.post("/items")
|
| 24 |
+
def update_item(item: Item):
|
| 25 |
+
return {"item_name": item.name, "twice price": item.price * 2}
|
|
|