How to Build an IBM i (AS400) API in 15 Minutes

ibm as400 mulesoft anypoint connector

This blog post is contributed by one of our partners, Infoview Systems. 

One of the biggest IT challenges is the growing IT delivery gap and the ever-increasing pace of business changes. This is especially true for established companies saddled with a mix of older applications. In order to efficiently connect these systems to other business components at scale, the application business logic and data must be packaged as easy-to-consume reusable assets.

Due to the monolithic nature, most legacy applications span multiple business domains. As a result, the number of required integrations is typically high. When we consider the complexity of integrating with legacy systems, the shortage of specialized skills, and tight budgets, it’s easy to see why unlocking ERP data and logic is a constant concern for IT leaders.

Technically, this problem boils down to the question: how fast can you build an API that calls the backend business logic, and how much of that work depends on the legacy team? In this how-to guide, I’ll show you how to use the latest version of MuleSoft’s Anypoint Connector for IBM i (AS400) to accelerate wrapping business logic program into a REST API without any IBM i tools or development required. Once the IBM i (AS400) API is developed, it can be plugged into Anypoint Platform for added security, governance, and operational insight.

Use Case

Suppose a company is implementing a new order channel for an IBM i based ERP. The ERP has a generic RPG program that already implements all the necessary validations and business logic for creating the order and pushing it through the fulfillment flows. The purpose of this task is to expose that Create Order program to other systems as an easy-to-consume System API.

Implementation

Below is a simplified RPG program definition that we will use for this example – it takes in the order ID and a list of up to 10 line items (each consisting of item code, quantity, and price).

ibm mulesoft

1. We start with building RAML definition for the API, matching the parameter structure:

2. Next, right-click on the RAML definition in Anypoint Studio and auto-generate the API scaffolding using APIKit. Method post:/orders:apiConfig will initially return the sample response defined in the RAML above.

3. Finally, we need to implement the program call. Drag the IBM i (AS400) connector to post:/orders:apiConfig flow, set the connection parameters and test the connection:

ibm as400 mulesoft

4. Select the Program Call operation and set the program name, library, and parameters.

5. Click on the plus sign and fill in parameter details. Pass parameter values from API request body to input or input parameters.

ibm as400 connector

6. For the order lines data structure, specify the data type as STRUCTURE, count of 10 (as this is an array of structures), and define nested data structure fields. Similarly, define the return data structure for lines returned back.

7. Switch to XML view and confirm the correct sequence of the parameters. Because of the way that Anypoint Studio handles lists of parameters, the order of elements in the list may change. The RPG program requires the parameters to be passed in exactly the same order as they are defined in the program. The resulting program definition looks like this:

ibm as400 mulesoft

8. And, finally, stick a transformer that converts the API request body to Java map. You can either use DataWeave or a Byte Array to Object transformer and specify target class java.util.Map. I prefer to use DataWeave:

And that, ladies and gentlemen, is how you build an IBM i API using MuleSoft in 15 minutes!

Run the application, and test it by posting the sample request using the Anypoint Studio API console or any other API client, like Postman:

mulesoft connector ibm

The RPG program I am using for this demo, intentionally updates the values of the order ID and line item details, adding 100 to order ID, concatenates item numbers using “out” and adds 20 to quantity and 10 to price. There’s no reason behind this other than to show that the data has been transformed on the IBM i back-end.

Final thoughts

It took just a few minutes to expose the IBM i business logic program as a reusable and easy-to-consume order entry API. We received the program name, library, and parameters as an input for our task, created RAML schema and/or examples to match the request and response structures, and then defined the parameters in the IBM i (AS400) connector.

Best of all, in most scenarios there’s no need to develop or run any additional components on the IBM i server, and MuleSoft developers only need to obtain the program attributes and parameters.

You can find the complete code for this example here.

Of course, this is a demo application that should normally be hardened with exception handling, logging, etc. In some cases, the request or response structures are too complex to fit into program parameters, and have to be passed to ERP business logic programs via DB2 staging tables. This blog article explains how IBM i Web Transaction Framework can simplify and streamline the API development for such use cases.

Connecting, modernizing, or migrating off of legacy systems is a complex undertaking. Based on my experience, failure rates in legacy ERP modernization and migration initiatives tend to be high. Anypoint Platform and IBM i (AS400) connector provide a comprehensive toolset for rapidly unlocking legacy business logic. The technology, along with a capable cross-functional delivery team, greatly improves the odds of project success and reduces the costs of large-scale legacy modernization and migration projects.

This blog post was first published on the Infoview Systems Blog.


 

We'd love to hear your opinion on this post


One Response to “How to Build an IBM i (AS400) API in 15 Minutes”

  1. We have a large table with millions of rows. I am building a Mule service that takes those records, creates a CSV file, and uploads it to an FTP. My question is, does this connector allow record-by-record streaming, so that the entire dataset is not put in memory?