IBM i > DEVELOPER > RPG

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 midrange.com 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: http://xyz.com/price/P2058/50 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: http://xyz.com/price?part=P2058&quantity=50

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
Buyers Guide

Advertisement

New and Improved XML-INTO

Namespace support makes the opcode a viable option

Authenticating on the Web

The finer points of OpenRPGUI, Part 1

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

Advertisement