flask api response code

To set the response code in Flask API, follow these steps:

  1. Import the necessary modules: python from flask import Flask, jsonify

  2. Create a Flask application: python app = Flask(__name__)

  3. Define a route with a function that returns the response with the desired status code: python @app.route('/example') def example(): response = jsonify({'key': 'value'}) response.status_code = 201 return response

  4. Run the Flask application: python if __name__ == '__main__': app.run()