Performance: Health check endpoints
Health check endpoints affect server responsiveness and overall user experience by ensuring quick status reporting without blocking main application processes.
from flask import Flask app = Flask(__name__) @app.route('/health') def health_check(): # Simple quick check return {'status': 'ok'}
from flask import Flask app = Flask(__name__) @app.route('/health') def health_check(): # Simulate heavy database query result = complex_database_query() return {'status': 'ok', 'db': result}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy database query in health check | 0 (API only) | 0 | 0 | [X] Bad |
| Simple static response in health check | 0 (API only) | 0 | 0 | [OK] Good |
/health?
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/health')
def health():
return jsonify(status='ok', uptime=12345)from flask import Flask
app = Flask(__name__)
app.route('/health')
def health():
return {'status': 'ok'}@app.route('/path') decorator above the function definition. The @ symbol is required to apply the decorator.app.route('/health') without the @, so it calls the route method but does not decorate the health function. Thus, the /health endpoint will not be registered and accessing it returns 404.Pass the test and this pattern moves unknown