The before code lacks any endpoint to report service health, so external systems cannot verify if the service is alive. The after code adds a '/health' endpoint that returns a simple JSON status. Load balancers or monitors can call this endpoint to check if the service is healthy and route traffic accordingly.
### Before: No health check endpoint
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello World'
### After: Adding a health check endpoint
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello World'
@app.route('/health')
def health_check():
# Simple health check returning service status
status = {'status': 'healthy'}
return jsonify(status), 200