Complete the code to create a basic Flask app with a health check endpoint at '/health'.
from flask import Flask app = Flask(__name__) @app.route('/health') def health_check(): return [1]
The health check endpoint should return a simple string like "OK" to indicate the app is running.
Complete the code to run the Flask app only when the script is executed directly.
if __name__ == [1]: app.run(debug=True)
The special variable __name__ equals "__main__" when the script is run directly.
Fix the error in the health check route to return a JSON response with status code 200.
from flask import jsonify @app.route('/health') def health_check(): return jsonify(status='OK'), [1]
HTTP status code 200 means the request was successful.
Fill both blanks to create a health check endpoint that returns JSON with a message and status code 200.
from flask import Flask, jsonify app = Flask(__name__) @app.route([1]) def health(): return jsonify([2]='Healthy'), 200
The route should be '/health' and the JSON key should be 'message' for clarity.
Fill all three blanks to create a Flask app with a health check endpoint that returns JSON with 'status', 'uptime', and HTTP 200.
from flask import Flask, jsonify import time app = Flask(__name__) start_time = time.time() @app.route([1]) def health_check(): uptime = time.time() - [2] return jsonify([3]='OK', uptime=uptime), 200
The route is '/health', uptime is calculated from start_time, and JSON key is 'status'.