IBM i > Developer > RPG

Need a REST?

Building REST Web Services With RPG


Bookmark and Share

Let’s look at the pertinent parts of the code:

(A) GetHTMLIFS( ‘/Partner400/RESTSRV1.xml’: ‘< !-- ‘: ‘ -- >‘);
    WrtSection(‘ResponseHeader’: *off: ‘‘);
    // Use getEnv to grab the back end of the URL

(B) pathInfo = getEnv(‘PATH_INFO’: qusec );
    // parse the path string to extract the individual pieces

(C) elementCount = ParsePath( pathInfo: elementList);
    // Loop through resulting list of elements

(D) For i = 1 to elementCount;
      ...
      WrtSection(‘responseBody’: *off: ‘‘);
    EndFor;
    // All completed - add trailer to buffer and send response

(E) WrtSection(‘responseTrailer *fini’: *off: ‘‘);

(A) This first section deals with preparing to send the response. The file RESTSRV1.xml contains the skeleton for the XML response document we’ll be generating and the write adds the standard HTTP response header to the buffer. Think of it as writing the page headers for a report before you start the main processing. If you want to know more about generating XML in this way, see “Using CGIDEV2 for Generating XML.

(B) Next we used the getEnv function to retrieve the environment variable PATH_INFO. This contains the portion of the URL after the part used by Apache to route the message to the program. If the original URL was http://www.mysystem.com/restsrv1/part1/part2 then PATH_INFO would contain “/part1/part2”.

(C) The next order of business is to parse the path to break out the various part numbers. This is the purpose of the function ParsePath, which returns a count of the number of parts it encounters. We’ll look at the code in a moment.

(D) Having identified the individual part numbers, we then loop through, processing each of them in turn and adding their data to the buffer.

(E) Once all parts have been processed, we simply write the response trailer and the special section *fini to cause the response to be sent.

Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Advertisement

Buyers Guide

Search our new 2013 Buyer's Guide.

Search Companies


Search Products


Advertisement

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link

Related Articles

New and Improved XML-INTO

E-Newsletter | Namespace support makes the opcode a viable option

Authenticating on the Web

E-Newsletter | The finer points of OpenRPGUI, Part 1