skip to main content

Web Service option : COBOL approach using REST : COBOL REST consumer

COBOL REST consumer
In order to develop a COBOL REST consumer (client-side), to invoke REST Web Service, the COBOL program should take advantage of HTTPClient class that allows to communicate with COBOL REST producer entry points through HTTP protocol. Also to allow definition of HTTP parameters, an HTTPData.Params class is provided.
In the isCOBOL sample folder you find the folder eis/webservices/rest/client that contains an example of COBOL client program called "CLIENTH.cbl" of previous "ISFUNCTIONS.cbl" server service.
This program has the objective to invoke ISFUNCTION_GETZIP service and ISFUNCTION_GETCITY to have the zip code of San Diego and to have the name of the city whose zip code is 89044.
This program must take the following steps:
           class http-client as "com.iscobol.rts.HTTPClient"
           class http-param  as "com.iscobol.rts.HTTPData.Params".
           http:>doGet("http://127.0.0.1:8080/isfunctions/servlet/isCobol(ISFUNCTIONS)")
           http:>getResponseCode (response-code)
          move "San Diego" to city-zipCode.
          set params = http-param:>new():>add("get_Zip_Code", city-zipCode).
           http:>doGet ("http://127.0.0.1:8080/isfunctions/"
           http:>getResponseCode (response-code)
           if response-code = 200
              http:>getResponseJSON (isfunction-recivedZipCode)
where isfunction-receivedZipCode working storage structure is defined like:
       01  isfunction-recivedZipCode identified by "".
            03 identified by "Zip_Code".
               05 zipCode  pic x any length.
and 92123 is the zip code of San Diego saved into zipCode COBOL variable.
A similar approach should be the following, have the city name provide the zip code.
this is the result:

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left