EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only

Service Library Function getRestresponseheader

By Nandhini A posted yesterday

  

IBM Rational Business Developer (RBD) version 9.7 introduced a powerful new service library function—getRestResponseHeaders which enhances the capabilities of EGL (Enterprise Generation Language) Java clients when interacting with RESTful services.

The getRestResponseHeaders function allows developers to retrieve the HTTP response headers from a variable used to access a REST service. This function is particularly useful when you need to inspect metadata such as content type or custom headers returned by the service.​

Syntax:

serviceLib.getRestResponseHeaders(variable Service | Interface in) returns (headers Dictionary)

variable: A variable based on a Service or Interface part that is used to access the REST service.

headers: A dictionary where each entry's key is the name of an HTTP header, and the corresponding value is the header's value

This blog explains how the EGL Java REST clients can see the HTTP response headers.

Java Client:

1.     Create General project.

a.     Go to File and Navigate to NewàEGL Project.

b.     Provide the Project name (GeoName) and select General Project under the EGL project types.

c.     Click Next.

d.     Select Java under the Target runtime platform and Create a build descriptor under Build descriptor options.

e.     Click Finish.

f.      The General project under Project Explorer has been created successfully.

2.     Create a Record:

a.     Go to File and navigate to NewàRecord.

b.    A New EGL Record window will appear.

c.     Provide the Package name and EGL source file name.

d.     Click Next.

e.     Select Basic from the Templates and click Finish.

f.      Record created and opened in EGL editor

Copy and paste the code below from here to the above file.

MyRecord.egl

package records;

Record MyRecord

      name string;

      age int;

      count int;

end

3.     Create an Interface:

a.     Right-click the project GeoName and navigate to NewàInterface.

b.     A New EGL Interface window will appear.

c.     Provide the Package name and the EGL source file name.

d.    Click Finish.

e.     listname.egl interface created and opened in EGL editor.

Copy and paste the code below into the above file listname.egl file.

listname.egl

package interfaces;

import records.MyRecord;

interface listname

    function searchJSON(query string in) returns(MyRecord){@GetRest{uriTemplate = "https://api.agify.io/?name={query}",

    responseFormat = JSON}};

end

4.     Creating a Program:

a.     Go to File and navigate to NewàProgram.

b.     A New EGL Program window will appear.

c.     Provide the Package and EGL source file name.

d.     Click Finish.

e.     invokeservice.egl file created and opened in EGL editor.

Copy and paste the code below into the above invokeservice.egl file.

invokeservice.egl

package programs;

import interfaces.listname;

import records.MyRecord;

program invokeservice type BasicProgram{}

    function main()

        lname listname{@BindService{}};

       query string = "meelad";

        lname.searchJSON(query);

        res dictionary = servicelib.getRestResponseHeaders(lname);

        si int = res.size();

        mykeys string[] = res.getKeys();

           syslib.writeStdout("Number of Response header received"+" "+"="+" "+si);

        for(i int from 1 to mykeys.getSize())

            syslib.writestdout("entry " + mykeys[i] + " :: " +

                            res[mykeys[i]]);

        end

    end

end

5.     Service Binding: Open deployment descriptor GeoName.egldd and open service binding tab

a.     Go to the GeoName.egldd project under the EGL Source.

b.     Go to the Service Bindings tab.

c.     Click Add…

d.     Add a Service Binding window will appear.

e.     Select REST service binding option under Binding Types.

f.      Click Next.

g.     Click Browse and select listname.

h.     Click Ok.

i.       Click Finish.

6.     Right-click on the general project (GeoName.egl).

7.     Select Generate.

8.     A Java program gets generated along with Interfaces and records.

9.     Under the EGLGen/JavaSource right-click on invokeservice.java.

10.  Select Run asàJava application.

11.  Response headers will be displayed in the console.

Here, the Content-Type header tells the client the format of the returned data.

 Content-Length indicates the size of the response body.

Response headers provide context, instructions, and additional information about the response itself, allowing clients to understand how to manage the returned data and resources.

Nandhini A

RBD QA Software Engineer.

0 comments
0 views

Permalink