How to call a REST API from COBOL

webMethods EntireX

Calling a REST API from COBOL is easy and straightforward with EntireX. Learn how EntireX can help you as an IT-professional and let COBOL benefit from the growing API economy. Read on to get an overview of COBOL calling REST API services.

By Jürgen Lind, Director Product Management Adabas & Natural, and Bernhard Fricke, Senior Software Specialist, EntireX Development, Software AG

Enrich your COBOL business logic with REST API services

Today’s new business initiatives are increasingly digital, with Internet-oriented interfaces, as well as business-to-business and business-to-consumer scenarios. At the same time, a huge amount of business logic exists in COBOL applications worldwide. These COBOL applications can fully benefit from the digital economy. Valuable COBOL business logic can be exposed as a REST API service. At the same time, COBOL applications can be enriched by calling REST API services that are internal or external to your organization.

Scenario

You want to call a REST API service within or external to your organization. As an example, imagine that a new order management system is being developed in your organization. A REST API placeOrder is provided. You’d like to call this REST API from your existing COBOL application. Using EntireX makes integrating these technologies easier than you think.

Calling a REST API from COBOL

Take an existing description of a REST API in the form of a swagger file and create the consumer REST API descriptor. Also, generate the connection and listener in Integration Server  1 . Then generate the COBOL client interface objects and build your COBOL application  2 . Execute the call from your COBOL client application to the REST API  3 .

Fig. 1: Scenario overview COBOL calls REST API

Create the consumer REST API descriptor, connection and listener  1 

Create the consumer REST API descriptor

Use a swagger file describing your REST API as input to create the REST API descriptor. In the Service Development perspective invoke the wizard to create a new REST API Descriptor:

Fig. 2: Create the consumer REST API descriptor

For more information on REST API descriptors see Service Development Help in the webMethods Integration Server documentation.

Extract the server interface and generate connections and listeners

Switch to EntireX perspective. Invoke the IDL Extractor for webMethods IS. Set COBOL as the target, to optimize the extracted IDL.

Fig. 3: Extract IDL and generate connections and listeners

After extraction, we recommend you use the Software AG IDL Tester to test the extracted IDL, the connection and listeners. On the context menu of the Software AG IDL file, select Software AG IDL Tester.

Generate client interface objects and build your COBOL client  2 

For COBOL code generation, make sure the EntireX perspective is active and invoke the COBOL Wrapper: on the context menu of the IDL file select COBOL > Generate RPC Client:

Fig. 4: COBOL Wrapper, generated COBOL source files

In the COBOL Wrapper, you can specify the names of the generated COBOL files to fit with your specific naming convention (Figure 4).

Test COBOL client calling the REST API  3 

To call and test the REST API directly from COBOL, use the generated COBOL client interface object source file (Figure 4) and build your COBOL application. If you have created the consumer REST API descriptor, there is no difference in the steps compared to calling a flow service in webMethods Integration Server from COBOL. Therefore a good source of further information is the earlier technical article “How to call webMethods Integration Server from COBOL – mainframe outbound”, TECHniques, October 2016 (Issue 4), which contains more detailed information.

Summary

As we have seen, with EntireX only a few clicks are required to enable a COBOL application to consume a REST API. Your mainframe application can participate in the rapidly growing API Economy. COBOL mainframe programs and REST - those irreconcilable technologies, originating from different decades – work together seamlessly.

Calling a REST API from COBOL has been available since EntireX version 10.5 (GA: 2019Oct). To learn more, read Common Integration Scenarios from the webMethods EntireX documentation.

Glossary of terms

API – Application Programming Interface
IDL – Interface Description Language
IS – webMethods Integration Server
JSON – JavaScript Object Notation; serialization standard; uses human readable text
REST – Representational State Transfer; architecture style to model structure and behavior of the World Wide Web
Swagger – Interface Definition Language for REST-APIs defined in YAML or JSON.
YAML – YAML Ain't Markup Language; serialization standard; superset of JSON 

Related articles

(1) Mainframe Integration made easy, TECHniques, April 2016 (Issue 2).
(2) How to call webMethods Integration Server from COBOL – mainframe outbound, TECHniques, October 2016 (Issue 4).
(3) How to call COBOL from webMethods Integration Server, TECHniques, April 2017 (Issue 2)
(4) How to shape a call to COBOL from webMethods Integration Server – the modern way, TECHniques, January 2018 (Issue 1).
(5) How to call COBOL on IBM i (AS/400) from Integration Server, TECHniques, July 2018 (Issue 3).
(6) Publish your mainframe assets as REST Resources, TECHniques, October 2018 (Issue 4).