Spaces:
Runtime error
Runtime error
fahmiaziz98 commited on
Commit ·
b08d3ea
1
Parent(s): 14067dc
frist commit
Browse files
app.py
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@app.get("/")
|
| 6 |
-
def
|
| 7 |
-
return {"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union
|
| 2 |
+
|
| 3 |
from fastapi import FastAPI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
|
| 9 |
+
class Item(BaseModel):
|
| 10 |
+
name: str
|
| 11 |
+
price: float
|
| 12 |
+
is_offer: Union[bool, None] = None
|
| 13 |
+
|
| 14 |
+
|
| 15 |
@app.get("/")
|
| 16 |
+
def read_root():
|
| 17 |
+
return {"Status": "Running"}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@app.get("/items/{item_id}")
|
| 21 |
+
def read_item(item_id: int, q: Union[str, None] = None):
|
| 22 |
+
return {"item_id": item_id, "q": q}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@app.put("/items/{item_id}")
|
| 26 |
+
def update_item(item_id: int, item: Item):
|
| 27 |
+
return {"item_name": item.name, "item_id": item_id}
|