srinuksv commited on
Commit
3d0cead
·
verified ·
1 Parent(s): b1875d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,20 +1,24 @@
1
- from fastapi import FastAPI
2
- from fastapi.responses import HTMLResponse
3
 
4
  app = FastAPI()
5
 
6
-
7
  @app.get("/")
8
- def home():
9
- html_content = open('index.html').read()
10
- return HTMLResponse(content=html_content, status_code=200)
 
 
 
 
 
11
 
 
 
 
12
 
13
- @app.get("/hello")
14
- def hello():
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