File size: 682 Bytes
1e78dcf
07221e5
1e78dcf
07221e5
1e78dcf
 
 
 
 
 
 
 
 
 
 
 
 
 
a66f784
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from fastapi import FastAPI, Request

app = FastAPI()

@app.post("/")
async def log_json(request: Request):
    try:
        # Parse the JSON body from the request
        json_body = await request.json()
        # Log the JSON payload to the console
        print("Received JSON payload:", json_body)
        # Respond with a success message
        return {"status": "success", "message": "JSON payload logged successfully"}
    except Exception as e:
        # Handle cases where the request body is not valid JSON
        print("Failed to parse JSON payload:", e)
        return {"status": "error", "message": "Invalid JSON payload"}, 400
:contentReference[oaicite:2]{index=2}