IBM i > DEVELOPER > RPG

Need a REST?

Building REST Web Services With RPG


Having told you what this second version does, let’s take a quick look at the underlying code. The first steps in the process (obtaining the skeleton and writing the response header) are the same as in the first example so we’ve omitted them here.

(F) pathInfo = getEnv(‘PATH_INFO’: qusec );
    service = %Subst(pathInfo: 2);

(G) inputCount = ZhbGetInput(savedQuery: QUSEC);
    // Assume the part number is present and go get it
    partNum = ZhbGetVar(‘partnum’);
    ...

(H) Select;
      When service = QUANTITY_QUERY;
        CheckQuantity(partNum);
      When service = PRICE_QUERY;
        CheckPrice(partNum);
    ...

(I) Other; // Unknown request - build error response
        request = getEnv(‘QUERY_STRING’: qusec );
        ...
        WrtSection(‘ServiceError’);

(F) As before, we’re using getEnv to obtain the path information because that will give us the name of the requested service.

(G) Next we call ZhbGetInput, which parses the query string, extracts the parameters and stores them for subsequent retrieval by ZhbGetVar. In this program, we’re not using the count returned by the API but it can be useful in determining how many parameters are present.

(H) All that remains is to direct the processing based on the specific service being requested.

(I) If the service name requested is unknown, then the complete query string is retrieved to assist in error reporting. You see the result of this for yourself by modifying the URL we gave you earlier.

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