Calling All Web Services
(From Your RPG Programs!)

DevelopmentIntegrationSecurity

 

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:

  • JSON Parsing in JavaScript: JSON is JavaScript Object Notation – it was built for JavaScript. Consequently, we moved all of the JSON parsing to JavaScript. This dramatically simplified the process (it took one line of JavaScript code).
  • 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.
    • When the JavaScript receives the JSON response, it parses the JSON and transforms it back to parameter data
    • It then places the results on a data queue to be read by the RPG program.
  • Handling Data Anomalies in JavaScript: JavaScript is very good at handling data in unpredictable formats. It can transform that data into the appropriate format for the RPG program – even if the structure changes.
  • Handle Unpredictability with a Flexible Language: If the JSON structure changes, JavaScript will handle it automatically. If the Web Service changes to HTTPS or HTTP/2, we change one line of code and JavaScript will handle the rest. If we decide to build real-time dashboards, JavaScript natively supports the WebSocket protocol. And if we decide to implement an IoT system with MQTT, there are many popular Open Source modules that perform every function we need with just a few lines of code.

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.

Want to learn more?  Watch our 3-minute video on Calling Out to Public Web Services Right from RPG Applications below.

 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!

 

Get the latest Eradani Blog posts sent to your email.

Facebook
Pinterest
Twitter
XING
LinkedIn
WhatsApp