Skip to content

IBM i and modern applications: integration through REST APIs

B2Bnetwork team · · 7 min

IBM i, RPG and mainframe

In brief

IBM i connects to modern applications through REST in both directions. You expose RPG programs and procedures as REST services through IWS (Integrated Web Services) or through your own service in Node.js or Python running on the same server. When IBM i has to call someone else's API, you use the HTTP functions in Db2 for i SQL and the JSON support in SQL and RPG. The business logic stays in one place, and the web shop or mobile app gets an ordinary API with JSON.

Two directions of integration

Integration with IBM i goes in two directions, and each is solved with different tools.

DirectionExampleTypical tools
Other systems call IBM iA web shop checks stock level and priceIWS, a Node.js or Python service in PASE, SQL procedures through JDBC/ODBC
IBM i calls other systemsA program fetches exchange rates or sends an order to a courierHTTP functions in SQL (QSYS2), HTTP libraries in RPG, scripts in PASE

In both cases it is worth starting with the question of which logic you are exposing. The best candidate is a procedure in a service program that takes parameters and returns a result, with no screens and no dependence on job state. If the logic sits today in a 5250 screen program, the first step is to extract it. We write about how to prepare the code in the article RPG today: free-form and modern tools.

IWS: RPG programs as REST services

IWS (Integrated Web Services) is a web services server built into IBM i. It lets you expose a program or a procedure in an ILE service program (RPG, COBOL) as a REST or SOAP service without writing your own HTTP layer. The service is configured in the administration panel of the IBM i HTTP server: you point to the program, map parameters to the path, query, or request body, and choose the response format, for example JSON.

An example from a wholesaler: a procedure that checks product availability takes an item number and a warehouse and returns the quantity and delivery date. After it is exposed through IWS, the web shop calls an address like “/web/services/availability/12345” and gets JSON, while the procedure is the same one the 5250 screen uses.

IWS works well when there are a few or a dozen services with a simple structure. With more services, complex responses, or a need for your own logic (versioning, aggregating several calls), many teams choose a service in Node.js or Python.

A Node.js or Python service in PASE

PASE (Portable Application Solutions Environment) is an AIX-compatible environment in which Node.js, Python, and other open source tools installed with the RPM package manager run on IBM i. A REST service written in such a language runs on the same server as the database and the RPG programs.

A typical setup:

  1. The Node.js or Python service accepts an HTTP request and checks permissions.
  2. Data is read directly through SQL from Db2 for i (an ODBC driver).
  3. The business logic is called as an SQL stored procedure that wraps an RPG program, or through a program-call library (XMLSERVICE and wrappers around it).
  4. The response comes back as JSON.

The advantage of this approach is full control over the API: paths, versions, validation, OpenAPI documentation. The disadvantage is extra code to maintain and a second language on the team.

IBM i as a client: calling someone else's API from SQL

When a program on IBM i has to fetch data from outside, the simplest way is to use the HTTP functions in the QSYS2 schema, for example QSYS2.HTTP_GET and QSYS2.HTTP_POST. You call them in an ordinary SQL query, including from an RPG program.

Db2 for i also builds JSON from table data, which is useful when sending orders to another system:

SELECT JSON_OBJECT(
         'order'    VALUE o.ordno,
         'customer' VALUE o.custno,
         'value'    VALUE o.ordvalue
       ) AS document
  FROM orders o
 WHERE o.ordno = 50012;

In the other direction, the JSON_TABLE function turns a JSON response into rows and columns, and in RPG the DATA-INTO statement loads a document into a data structure. HTTPS connections require trusted certificates, which are managed on IBM i in DCM (Digital Certificate Manager).

What about exchange files and batch integration

Many companies exchange data with IBM i today through files: a CSV export at night, an FTP transfer, an import on the other side in the morning. REST does not have to replace all such flows right away.

Files still make sense for large batches of data once a day, for example when feeding a data warehouse. Where freshness matters, for example stock levels in a web shop or order status for a customer, an API gives an answer at the moment of the question instead of data that is several hours old.

A good order is to start with the flow that hurts the business most: usually data that someone waits for until morning, or manual retyping between systems. For the remaining file flows, it is worth at least moving to encrypted transfer, for example SFTP, and documenting them in one place.

Security and performance

A REST service opens up a system that for years was reachable only from the internal network. A few rules save trouble:

  • Encryption. HTTPS only, with a certificate managed in DCM or on an API gateway in front of IBM i.
  • Authentication. A token or client certificate, checked before the logic is called. A service should not accept IBM i user profile passwords from external applications.
  • Least privilege. The service job runs under a profile that has access only to the objects it needs. A profile with the *ALLOBJ authority is not suitable for web services.
  • API gateway. Call limits, logging, and versioning are easier to handle on a gateway in front of IBM i than in each program separately.
  • Measurement before exposure. A procedure written for one screen may not withstand peak traffic from a web shop. A load test on a copy of the environment will show this before your customers do. The types of such tests are described in the article Load, stress, and endurance tests, and the scope of our performance testing in the section What we do.

We compare API styles beyond IBM i in the article REST, GraphQL, or gRPC: how to choose an API style.

Questions and answers

Do you have to rewrite RPG programs to expose an API from IBM i?

Usually not. If the logic is in a procedure or program that takes parameters and does not use a screen, it can be exposed right away through IWS or called from a Node.js or Python service. A rewrite is needed when the logic is mixed with 5250 screen handling. Then you extract it into a service program used by both the screen and the API.

Which to choose: IWS or your own Node.js service?

IWS is simpler when there are few services, they have a simple structure, and the team knows mostly RPG. Your own service in Node.js or Python gives more control: versioning, validation, combining several calls, and OpenAPI documentation, but requires maintaining another language. Many companies start with IWS and switch to their own service as the API grows.

Can IBM i send data to other systems in real time?

Yes. A program can call someone else's API at the moment of an event, for example with the QSYS2.HTTP_POST function after saving an order. With heavier traffic, a queue works better: IBM i records the event, and a separate process sends it on, for example to Kafka, with retries on errors. Then a failure on the receiving side does not stop work on IBM i.

How do you test REST services exposed from IBM i?

The same way as any other API: contract tests, functional tests with edge-case data, and load tests. API testing tools work independently of the platform, so nothing needs to be installed on IBM i. On the IBM i side, it is worth preparing a library with test data so that the tests do not use production. More in the article Automated tests for IBM i applications.

What it looks like in a project

Developing a system on IBM i or mainframe? Talk to an RPG engineer.

Let's talk

Read more: IBM i, RPG and mainframe