Bird
0
0

Which of the following is the correct way to define a simple health check endpoint in Flask?

easy📝 Syntax Q12 of 15
Flask - Deployment
Which of the following is the correct way to define a simple health check endpoint in Flask?
Aapp.route('/health') def health(): return {'status': 'ok'}
B@app.route('/health') health = {'status': 'ok'}
Capp.route('/health') health = lambda: {'status': 'ok'}
D@app.route('/health') def health(): return {'status': 'ok'}
Step-by-Step Solution
Solution:
  1. Step 1: Recall Flask route decorator syntax

    Flask uses @app.route('/path') decorator above a function to define routes.
  2. Step 2: Check each option for correct syntax

    @app.route('/health') def health(): return {'status': 'ok'} correctly uses @app.route decorator and defines a function returning a dictionary. Others miss the decorator or define incorrectly.
  3. Final Answer:

    @app.route('/health')\ndef health():\n return {'status': 'ok'} -> Option D
  4. Quick Check:

    Use @app.route decorator for routes [OK]
Quick Trick: Use @ before app.route to define Flask routes [OK]
Common Mistakes:
MISTAKES
  • Forgetting the @ symbol before app.route
  • Returning a dictionary without a function
  • Assigning route to a variable instead of a function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes