Flask API Fundamentals · Flask Basics

Create Your First API

Build a tiny JSON endpoint and understand the app object.

Create Your First API

Flask is intentionally small. You create an app, register routes, and return responses. For API work, that usually means returning JSON rather than rendering HTML templates.

Minimal App

from flask import Flask, jsonify

app = Flask(__name__)


@app.get('/health')
def health_check():
    return jsonify(status='ok')


if __name__ == '__main__':
    app.run(debug=True)

What Matters

  • @app.get(...) maps an HTTP method and path to a function.
  • jsonify(...) turns Python data into a JSON response.
  • debug=True is useful locally, but should stay off in production.

Try It

Add a /greet route that returns {"message": "hello"} and then extend it to accept a name in the query string.

Open in the app to mark lessons complete, take notes and track your progress.