File size: 700 Bytes
3d0cead
 
950525a
 
 
3d0cead
950525a
3d0cead
 
 
 
 
 
 
 
950525a
3d0cead
 
 
950525a
3d0cead
 
950525a
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from fastapi import FastAPI, Request
import json

app = FastAPI()

# Define the default root route (GET request) for the homepage
@app.get("/")
async def root():
    return {"message": "Welcome to the FastAPI Webhook Server!"}

# Define a POST route that receives data and returns a success message
@app.post("/webhook")
async def webhook(request: Request):
    # Retrieve JSON data from the POST request
    data = await request.json()

    # Save data to a file or perform any other operation
    with open("received_data.json", "w") as f:
        json.dump(data, f)

    # Return a success message
    return {"status": "success", "message": "Data received successfully", "received_data": data}