vhr1007 commited on
Commit
d364534
1 Parent(s): 53e7a1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -4
app.py CHANGED
@@ -1,9 +1,29 @@
1
  from fastapi import FastAPI
 
 
 
 
 
 
 
 
2
 
3
  app = FastAPI()
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.get("/")
6
- def greet_json():
7
-
8
- return {"Hello": "World!"}
9
-
 
1
  from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+
4
+ # Define a Pydantic model for the request body
5
+ class Item(BaseModel):
6
+ name: str
7
+ description: str = None
8
+ price: float
9
+ tax: float = None
10
 
11
  app = FastAPI()
12
 
13
+ # Define a simple POST endpoint
14
+ @app.post("/items/")
15
+ async def create_item(item: Item):
16
+ # Perform some processing with the item data
17
+ total_price = item.price + (item.tax if item.tax else 0)
18
+ return {
19
+ "name": item.name,
20
+ "description": item.description,
21
+ "price": item.price,
22
+ "tax": item.tax,
23
+ "total_price": total_price,
24
+ }
25
+
26
+ # Define a simple GET endpoint
27
  @app.get("/")
28
+ async def read_root():
29
+ return {"message": "Welcome to my FastAPI deployment on Hugging Face!"}