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;
      When service = PRICE_QUERY;

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

(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



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