-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
39 lines (31 loc) · 960 Bytes
/
api.py
File metadata and controls
39 lines (31 loc) · 960 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, request, jsonify
import logging
import os
app = Flask(__name__)
# Set up logging
logging.basicConfig(level=logging.INFO)
@app.before_request
def log_request_info():
logging.info('Request: %s %s', request.method, request.url)
@app.after_request
def log_response_info(response):
logging.info('Response: %s %s', response.status, response.response)
return response
# Root endpoint
@app.route('/', methods=['GET'])
def root():
return jsonify({"msg": "BC4M"})
# Health check endpoint
@app.route('/health', methods=['GET'])
def health():
# Simple health check
return jsonify({"status": "healthy"})
# POST endpoint
@app.route('/', methods=['POST'])
def echo():
data = request.get_json()
if not data:
return jsonify({"error": "Invalid JSON"}), 400
return jsonify(data)
if __name__ == '__main__':
app.run(host=os.getenv('FLASK_HOST', '0.0.0.0'), port=int(os.getenv('FLASK_PORT', 5000)))