Bird
0
0

What is wrong with this Flask health check endpoint code?

medium📝 Debug Q7 of 15
Flask - Deployment
What is wrong with this Flask health check endpoint code?
from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/health')
def health():
    return jsonify(status='ok'), 201
A201 status code is inappropriate for health check
Bjsonify cannot be used with status codes
CRoute decorator syntax is invalid
DFunction must return a string, not jsonify
Step-by-Step Solution
Solution:
  1. Step 1: Understand HTTP status codes for health checks

    Health checks typically return 200 OK, not 201 Created which means resource creation.
  2. Step 2: Confirm jsonify usage and syntax

    jsonify can be returned with a status code tuple; syntax is valid.
  3. Final Answer:

    201 status code is inappropriate for health check -> Option A
  4. Quick Check:

    Use 200 OK for health checks, not 201 [OK]
Quick Trick: Use 200 OK status for health checks [OK]
Common Mistakes:
MISTAKES
  • Using 201 instead of 200
  • Thinking jsonify disallows status codes
  • Confusing route decorator syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes