Article
· 23 hr ago 3m read

Hosting a Flask REST API on InterSystems IRIS using WSGI

For my intern project, I am building a Flask REST API backend. My goal is to host it on InterSystems IRIS using the WSGI interface. This is a relatively new approach and is currently only being used in a handful of projects such as AskMe. To help others get started, I decided to write this article to simplify the process.

 

Creating a Basic Flask App

First, let’s create a minimal Flask application. Here is the code:

from flask import Flask
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

@app.route('/test')
def test():
    return "Test"
if __name__ == "__main__":
    app.run()

This simple app runs a Flask server with one API endpoint at /test that returns the text “Test.”

 

Let's analyze our code line by line:

from flask import Flask
from flask_cors import CORS
  • We are using Flask as our web framework to build the REST API, so we import Flask .
  • CORS (Cross-Origin Resource Sharing) is imported via flask_cors to allow requests from different domains (important for frontend apps hosted elsewhere to access your API without security errors).
app = Flask(__name__)
CORS(app)
  • We create an instance of the Flask application named app.
  • We then wrap this app with CORS middleware, enabling cross-origin requests by default. Without this, browsers might block API calls from other domains.
@app.route('/test')
def test():
    return "Test"
  • Here we define a route /test using the @app.route decorator. This binds the URL /test to the Python function test().
  • When a user sends an HTTP GET request to /test, Flask will invoke the test() function, which simply returns the string "Test". This serves as a simple API endpoint for testing connectivity.
if __name__ == "__main__":
    app.run()
  • This block checks if the script is being run directly (not imported as a module).
  • If so, it starts Flask’s built-in development server locally on your machine.
  • Note: When deploying on InterSystems IRIS using WSGI, this section is ignored because IRIS manages the server.

 

Configuring the Web App on IRIS

Once your Flask app is ready, the next step is to host it on IRIS by configuring a Web Application with the WSGI option.

  1. Open the IRIS Management Portal for your instance.
  2. Go to System > Security Management > Web Applications or search Web Applications.
  3. Click the Create New Web Application button.
  4. Fill out the form as follows:
    • Name: Give your web app a path, for example: /csp/user/api.
    • Description: Add a brief description like My Flask API backend.
    • Enabled: Make sure this checkbox is checked.
  5. Scroll down and check the WSGI (Experimental) option to enable running Python WSGI apps.
  6. Then fill in the WSGI details:
    • Application Name: main (This corresponds to the WSGI callable you want IRIS to use.)
    • Callable Name: app (This matches the Flask application variable name in your code.)
    • WSGI App Directory: Enter the full file path to your main.py file where the Flask app is defined. For example: /path/to/main.py.
    • Debug: Unchecked
  7. Click Save.

 

Here’s what this configuration looks like in the portal:

 

 

 

Testing Your API

After saving, your Flask API should now be available at:

https://base.<your-domain>.com/csp/user/api/test or more generally, https://base.<your-domain>.com/<path>/test

 

Open this URL in your browser or test it using Postman or curl. You should see the response:

'Test'

 

What’s Next?

This setup lets you run a Flask REST API hosted directly on IRIS using the WSGI integration. From here, you can expand your API with more endpoints and connect to IRIS data sources to build powerful applications.

Put in the comments what you plan on building with Flask 
😜

Discussion (0)1
Log in or sign up to continue