0
0
Flaskframework~20 mins

Health check endpoints in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Health Check Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the output of this Flask health check endpoint?
Consider this Flask app code snippet for a health check endpoint. What will the endpoint return when accessed?
Flask
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/health')
def health_check():
    return jsonify(status='ok', uptime=12345), 200

# Assume the server is running and /health is accessed
A{"status":"ok","uptime":12345}
BInternal Server Error
C404 Not Found
Dstatus=ok, uptime=12345
Attempts:
2 left
💡 Hint
Flask's jsonify returns JSON with correct headers.
📝 Syntax
intermediate
1:30remaining
Which option causes a syntax error in this Flask health check route?
Identify which Flask route definition will cause a syntax error.
Flask
from flask import Flask, jsonify
app = Flask(__name__)

# Four route definitions below
A@app.route('/health')\ndef health()\n return jsonify(status='ok')
B@app.route('/health')\ndef health():\n return jsonify(status='ok')\n print('done')
C@app.route('/health')\ndef health():\n return jsonify(status='ok')
D@app.route('/health')\ndef health():\n return jsonify(status='ok', code=200)
Attempts:
2 left
💡 Hint
Check for missing colons in function definitions.
state_output
advanced
1:30remaining
What is the HTTP status code returned by this health check endpoint?
Given this Flask health check endpoint, what HTTP status code will the client receive?
Flask
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/health')
def health_check():
    response = jsonify(status='ok')
    response.status_code = 503
    return response
A500
B200
C404
D503
Attempts:
2 left
💡 Hint
The status_code attribute sets the HTTP status code.
🔧 Debug
advanced
2:00remaining
Why does this Flask health check endpoint raise a TypeError?
Examine the code and identify why it raises a TypeError when accessed.
Flask
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/health')
def health_check():
    data = {'status': 'ok'}
    return jsonify(data, 200)
AMissing return statement causes TypeError
BThe dictionary 'data' is not JSON serializable
Cjsonify() does not accept multiple positional arguments like (data, 200)
DFlask app is not instantiated properly
Attempts:
2 left
💡 Hint
Check the signature of jsonify function.
🧠 Conceptual
expert
1:30remaining
Which option best describes the purpose of a health check endpoint in Flask?
Select the most accurate description of why a health check endpoint is used in a Flask application.
ATo authenticate users before accessing the main app routes
BTo provide a simple URL that returns the app's status for monitoring systems
CTo serve the main homepage content of the Flask app
DTo handle all errors and exceptions globally
Attempts:
2 left
💡 Hint
Think about monitoring and uptime checks.