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.
Search our new 2013 Buyer's Guide.
Maximize your IT investment with monthly information from THE source...IBM Systems Magazine EXTRA eNewsletter. SUBSCRIBE NOW.
View past IBMi EXTRAs here
Related Articles
E-Newsletter | Namespace support makes the opcode a viable option
E-Newsletter | The finer points of OpenRPGUI, Part 1