Need a REST?

Building REST Web Services With RPG

The ParsePath function is a very simple process that breaks the string into its individual components using the forward slash as the separator. The only twist is that the initial scan starts at position 2 because we know that the first character in PATH_INFO will be a forward slash. We loop through the string storing each of the elements extracted in the array elements for later processing. The code is shown below.

   DoU position = 0; // Quit when no more to process
     count += 1;
     position = %Scan(‘/’: path: start);
     If position > 0;
       elements(count) = %Subst(path: start: ( position -
       start = position + 1;
       // Last element has no trailing / so grab last piece
       elements(count) = %Subst(path: start);

Even though the data is intended for consumption by a program, because the request is in the form of a URL, you can test it in a browser—something you can’t do with a SOAP Web service. You can try out our sample service for yourself by using this URL: Add a few more part numbers to the URL and your browser should show you the XML that’s returned. Don’t expect it to look like much. Remember, it’s intended for consumption by a program, not a human.

Another Example

Our next example is of the second type—namely that the function required is specified in the URL but the specific parameters are in the query string. Our example supports such requests as:

Notice the function required (quantityquery) is in the URL but the parameters (partnum and quantity) are named parameters in the query string and not simply positional in the URL as in the first example. In fact, this program currently supports two types of requests—a quantity query (quantityquery) and a price query (pricequery). Anything else will be rejected with an error message. Don’t take our word for it—test it yourself by using the link above. We’ve listed a few valid part numbers at the end of the article if you want to explore a little further. Note that this service only supports requests for one part at a time.

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.

comments powered by Disqus



2017 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

New and Improved XML-INTO

Namespace support makes the opcode a viable option

Authenticating on the Web

The finer points of OpenRPGUI, Part 1

The Microphone is Open

Add your voice: Should IBM i include open-source RPG tools?

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters