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’);
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.
comments powered by