EGL Development User Group - Group home

See What i Can Do - V2R0 - Reprise

  
Okay, this was a lot easier than I expected. I'm not saying it didn't requier a little research; the QzhbCgiParse API is not for the faint of heart. But a little research, a little careful reverse engineering, and I was able to create a program that responds to a Rich UI REST request. And it takes nine lines:


QzhbCgiParse( '-v Cust': 'CGII0100': cust: %size(cust):
              bytesRead : dsError);
if (bytesRead > 1);
  cust = %subst( cust: 1: bytesRead-1);
endif;

data = 'Content-Type: text/html' + CRLF + CRLF;
QtmhWrStout(data: %len(data): dsError);

data = '{"result" : "' + 'Name-' +
       %trim(cust) + '"}' + CRLF;
QtmhWrStout(data: %len(data): dsError);

return;


The simplicity of the code is rather impressive. The first line gets the data from the URL, the next three strip off the trailing LF that QzhbCgiParse insists on giving you. The next two lines send the header, the last two send the response formatted as a JSON string. That's all there is to it. There are obviously a couple of prototypes, and the ubiquitous error data structure that is familiar to anybody who codes API calls in RPG, but those can be /COPY'd in. The meat of the code is the eight lines above (nine counting the return).

The code in the test program is even simpler:


testService testService { @RESTBinding
{baseURI =
"http://IRUIHOST/cgi-bin/RUIT1.PGM?Cust=77654"}};
call testService.getName()
returning to ts1listen
onException ServiceLib.serviceExceptionHandler;

It's a standard REST call, except I change the baseRUI to pass the parameters. Now, I haven't gotten around to figuring out how to pass the parameter via the actual method call, but for this particular proof of concept I don't care about that. The point of this exercise is to prove that anything you can do with "traditional" EGL - that is, a web service written in EGL and deployed in an application server that calls an RPG program - can be done using nothing but the Powered by Apache server and standard RPG-CGI - that is, no Java, no WebSphere, nothing you wouldn't have to know for any other approach. You just have to learn the EGL Rich UI syntax.

Now, I wouldn't recommend this approach since if you can write EGL Rich UI you can write host-based EGL just as easily, but if you absolutely cannot run WebSphere or Tomcat, then this will allow you to still use EGL Rich UI.

Nifty, huh?

Let me clean up the example to something a little less trivial and I'll post this project, probably tomorrow sometime. As I noted at the beginning, I'm doing this solely in my free time and I used up most of that time tonight writing this blog post.