0
0
Flaskframework~30 mins

Health check endpoints in Flask - Mini Project: Build & Apply

Choose your learning style9 modes available
Health Check Endpoints with Flask
📖 Scenario: You are building a simple web service that needs to report its health status. This is common in real-world apps to let monitoring tools check if the service is running well.
🎯 Goal: Create a Flask app with a health check endpoint /health that returns a JSON response showing the service status.
📋 What You'll Learn
Use Flask to create a web app
Create a route /health that returns JSON
Return a JSON object with key status and value "ok"
Set the HTTP status code to 200 for the health check response
💡 Why This Matters
🌍 Real World
Health check endpoints are used by monitoring systems to check if a web service is running and healthy.
💼 Career
Knowing how to create health check endpoints is important for backend developers and DevOps engineers to ensure service reliability.
Progress0 / 4 steps
1
Set up the Flask app
Import Flask from flask and create a Flask app instance called app.
Flask
Need a hint?

Use from flask import Flask and then app = Flask(__name__).

2
Create the health check route
Use the @app.route decorator with the path /health to define a function called health_check.
Flask
Need a hint?

Use @app.route('/health') above a function named health_check.

3
Return JSON response with status
Inside the health_check function, import jsonify from flask and return jsonify({'status': 'ok'}).
Flask
Need a hint?

Use return jsonify({'status': 'ok'}) inside the function.

4
Set HTTP status code to 200 explicitly
Modify the return statement in health_check to return the JSON and the status code 200 as a tuple.
Flask
Need a hint?

Return a tuple with jsonify({'status': 'ok'}) and 200.