How to call a REST API from COBOL
Tags: webmethods, cobol, rest, api
Published: 2020-02-03 12:44:28

---
title: How to call a REST API from COBOL
published: true
date: 2020-01-22 15:12:00 UTC
tags: #webmethods, #cobol, #rest, #api
canonical_url: http://techcommunity.softwareag.com/techniques-blog/-/blogs/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).

![](http://techcommunity.softwareag.com/documents/10157/11220621/EntireX_1.png/c1e9405a-f044-46ba-970b-3d845388aad6?t=1580129547113)

_**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_:

![](http://techcommunity.softwareag.com/documents/10157/11220621/EntireX_2.png/76a79ac8-ae4d-4a39-b1d0-789b57fbf18e?t=1580129550820)

_**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.

![](http://techcommunity.softwareag.com/documents/10157/11220621/EntireX_3.png/1b3c2d1d-a159-4660-8049-527215bce02d?t=1580129553613)

_**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_:

![](http://techcommunity.softwareag.com/documents/10157/11220621/EntireX_4.png/7c0101ae-479c-40b4-9247-a07d98410438?t=1580129557557)

_**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](http://techcommunity.softwareag.com/techniques-blog/-/blogs/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](http://documentation.softwareag.com/webmethods/wmsuites/wmsuite9-9/EntireX/9-9_EntireX/scenarios/overview.htm) 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](http://techcommunity.softwareag.com/techniques-blog/-/blogs/webmethods-entirex)”**, TECHniques, April 2016 (Issue 2).

(2) **“[How to call webMethods Integration Server from COBOL – mainframe outbound](http://techcommunity.softwareag.com/techniques-blog/-/blogs/how-to-call-webmethods-integration-server-from-cobol-mainframe-outbound)”**, TECHniques, October 2016 (Issue 4).

(3) **“[How to call COBOL from webMethods Integration Server](http://techcommunity.softwareag.com/techniques-blog/-/blogs/webmethods-entir-2)”**, TECHniques, April 2017 (Issue 2)

(4) **“[How to shape a call to COBOL from webMethods Integration Server – the modern way](http://techcommunity.softwareag.com/techniques-blog/-/blogs/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](http://techcommunity.softwareag.com/techniques-blog/-/blogs/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](http://techcommunity.softwareag.com/techniques-blog/-/blogs/publish-your-mainframe-assets-as-rest-resources)”**, TECHniques, October 2018 (Issue 4).