Pepguy commited on
Commit
1e78dcf
·
verified ·
1 Parent(s): 658e4f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,16 +1,19 @@
1
- from flask import Flask, request, jsonify
2
 
3
- app = Flask(__name__)
4
 
5
- @app.route('/webhook', methods=['POST'])
6
- def webhook():
7
- # Get the JSON data from the request
8
- data = request.get_json()
9
- # Log the JSON data to the console
10
- print("Received JSON:", data)
11
- # Respond back with a simple JSON message
12
- return jsonify({"status": "success", "message": "Data received"}), 200
 
 
 
 
 
 
13
 
14
- if __name__ == '__main__':
15
- # Run the Flask server on port 5000 with debug mode enabled
16
- app.run(debug=True, port=5000)
 
1
+ from fastapi import FastAPI, Request
2
 
3
+ app = FastAPI()
4
 
5
+ @app.post("/")
6
+ async def log_json(request: Request):
7
+ try:
8
+ # Parse the JSON body from the request
9
+ json_body = await request.json()
10
+ # Log the JSON payload to the console
11
+ print("Received JSON payload:", json_body)
12
+ # Respond with a success message
13
+ return {"status": "success", "message": "JSON payload logged successfully"}
14
+ except Exception as e:
15
+ # Handle cases where the request body is not valid JSON
16
+ print("Failed to parse JSON payload:", e)
17
+ return {"status": "error", "message": "Invalid JSON payload"}, 400
18
+ :contentReference[oaicite:2]{index=2}
19