How can I implement a simple REST API using Flask in Python?

95 views

How can I implement a simple REST API using Flask in Python?

How can I implement a simple REST API using Flask in Python?

solveurit24@gmail.com Changed status to publish February 13, 2025
0

Here’s a basic example using Flask:

from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/api')
def my_api():
    return jsonify({'message': 'Hello, World!'})

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

Explanation:

  • Flask is a lightweight web framework.
  • @app.route('/api') defines a route for the API.
  • jsonify converts a dictionary to a JSON response.

To run the app:

python app.py
solveurit24@gmail.com Changed status to publish February 13, 2025
0
You are viewing 1 out of 1 answers, click here to view all answers.