Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,24 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
-
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
-
|
7 |
@app.get("/")
|
8 |
-
def
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
return {"hello": "world"}
|
16 |
|
17 |
|
18 |
-
@app.get("/hello/{name}")
|
19 |
-
def greet(name):
|
20 |
-
return {"greeting": f"Hello {name}!"}
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
import json
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
+
# Define the default root route (GET request) for the homepage
|
7 |
@app.get("/")
|
8 |
+
async def root():
|
9 |
+
return {"message": "Welcome to the FastAPI Webhook Server!"}
|
10 |
+
|
11 |
+
# Define a POST route that receives data and returns a success message
|
12 |
+
@app.post("/webhook")
|
13 |
+
async def webhook(request: Request):
|
14 |
+
# Retrieve JSON data from the POST request
|
15 |
+
data = await request.json()
|
16 |
|
17 |
+
# Save data to a file or perform any other operation
|
18 |
+
with open("received_data.json", "w") as f:
|
19 |
+
json.dump(data, f)
|
20 |
|
21 |
+
# Return a success message
|
22 |
+
return {"status": "success", "message": "Data received successfully", "received_data": data}
|
|
|
23 |
|
24 |
|
|
|
|
|
|