flask get with parameters

from flask import Flask, request

app = Flask(__name__)

@app.route('/get_example', methods=['GET'])
def get_example():
    param_value = request.args.get('param_name')
    return f'The value of the parameter is: {param_value}'

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

Explanation:

  1. Import the necessary modules from Flask, including Flask and request.
  2. Create a Flask web application instance.
  3. Define a route '/get_example' that will be triggered when an HTTP GET request is made to this endpoint.
  4. Specify the allowed HTTP methods for this route as 'GET'.
  5. Define a function get_example() that will be executed when the route is accessed.
  6. Inside the function, use request.args.get('param_name') to retrieve the value of the query parameter named 'param_name' from the URL.
  7. Return a response containing the retrieved parameter value using an f-string.
  8. Run the Flask application with debugging enabled if the script is executed directly.