Need a REST?

Building REST Web Services With RPG

While it may not be technically correct in a purist sense, a definition of this type of RESTful service that we particularly like was proposed by RJS’ Richard Schoen in a discussion. Richard succinctly defined it this way:

“RESTful is anything where I can pass a formatted URL with parms of some sort and get data back in XML, JSON or whatever format I desire.”

Since REST services use the same HTTP protocol used by browsers, another way to think about it is that a RESTful service is a kind of “Web page” designed to be “read” by a program rather than by a human. That program could be anything from PHP to Java, to C# to RPG².

Now that we all know the scope of this discussion, let’s look at the two most common ways in which REST service requests are formed. Both use an HTTP GET request, but the method by which parameters are defined is quite different. There may be special names for the two types, but if so we haven’t encountered them.

  1. Those where the complete request is in the form of a URL. That is to say that both the function requested and its parameters are part of the URL. Parameters are simply identified by their relative position. An example might be: where “price” indicates the type of information required, “P2058” is the part number in question and “50” is the quantity to be priced. You can logically view this in the way it reads. For example, a directory named “price” contains a directory for every part we sell. Each of those directories in turn contains a file for each possible quantity and that file contains the relevant price. Of course, it’d be completely impractical to actually implement the system this way, but it may help to give you a mental model of why the request is formed the way it is.
  2. Those where the type of information requested (i.e., the action) is contained within the URL but the specifics are parameterized in the query string. Parameters are identified by name. For example:

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