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: http://systemideveloper.com:1241/restsrv1/part1/Part2/part3. 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.
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: http://systemideveloper.com:1241/restsrv2/quantityquery?partnum=0000011&quantity=5
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.