A customer asked me recently to help them solve the problem of directly calling web service APIs from RPG. They told me that their warehouse managers needed to ensure they had the right people and the right equipment at the loading dock when shipments arrive. They wanted to know if they could add a function to their RPG warehouse management application that would call out to web service APIs provided by their vendors to get shipment tracking numbers and then to use those numbers to call out to freight company APIs to get the shipment ETA. This would allow them to automate the scheduling process.
Some of the challenges they faced included:
- JSON Parsing: They had tried calling web services from RPG in the past but found that parsing JSON from the APIs (especially complex JSON with data structures and variable-length arrays) in RPG was difficult even with the tools available on the IBM i.
- Synchronous versus Asynchronous: Their IBM i RPG programs were procedural and synchronous while the web services were asynchronous.
- Input Control: In the web world, they lacked the control over the inputs that they had with IBM i display files – they were never sure exactly what they would get.
- Maintenance Headaches: What happens if the JSON structure of the API changes? Or the Web Service changes to HTTPS or HTTP/2? Or, I want to add a real-time dashboard that requires Web Sockets? Or, I need to add an IoT service that requires MQTT? With HTTP from RPG, maintenance is a major headache.
To overcome those challenges, we took these steps:
- Data Queues for Asynchronous Operation:
- The Warehouse application makes an RPG program call with parameters to the API.
- That call with its parameters is placed on a data queue.
- A Node.js application listens for entries on the data queue, takes the request from the queue and turns the parameters into JSON.
- It then executes the API call.
- It then places the results on a data queue to be read by the RPG program.
Since this discussion, the company has identified a variety of other opportunities to take advantage of web services from their RPG code. They can use it to access Maps information from Google, weather information, government data sources and services provided by their business partners. Using this technique makes it easy to add those services.
If you would like to learn more about how you can make it easy to call web services from your IBM i RPG programs, let us know. We can help you get started!