Flask route as API endpoint
📖 Scenario: You are building a simple web service that provides information about fruits. This service will have an API endpoint that returns fruit data in JSON format.
🎯 Goal: Create a Flask application with a route /api/fruits that returns a JSON response containing a list of fruits and their colors.
📋 What You'll Learn
Create a dictionary called
fruits with fruit names as keys and their colors as valuesCreate a Flask app instance named
appDefine a route
/api/fruits using the @app.route decoratorReturn the
fruits dictionary as a JSON response using jsonify💡 Why This Matters
🌍 Real World
APIs like this let apps and websites get data from servers in a simple, standard way.
💼 Career
Knowing how to create API endpoints with Flask is useful for backend web development jobs.
Progress0 / 4 steps