Is getenv('REQUEST_URI') required?

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
Post Reply
jarhead0311
Posts: 8
Joined: Wed Dec 21, 2022 4:32 pm

Is getenv('REQUEST_URI') required?

Post by jarhead0311 »

Can anyone tell me if a getenv('REQUEST_URI') is required? I'm creating a CGI program that will create a JSON file and send it to a URL without a requesting URI. The idea is that this program can be scheduled to run and send the data to the URL.

I have it working with a request_uri, but that's a GET operation. I would like to hard code the uri in a variable and just be able to call it as a POST to the URL. If anyone is doing this, I'd like to know how. Thanks!
jarhead0311
Posts: 8
Joined: Wed Dec 21, 2022 4:32 pm

Re: Is getenv('REQUEST_URI') required?

Post by jarhead0311 »

Well, I was able to do it, but I had to include HTTPAPI to do a POST to the URI. Not sure if that's the "best" way to do it, but it worked. ;)
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: Is getenv('REQUEST_URI') required?

Post by Scott Klement »

getenv('REQUEST_URI') is when writing a CGI program that runs under the IBM HTTP Server (powered by Apache). It lets you retrieve the URI (also called "URL") that the caller used to run your program.

You mention that you are using HTTPAPI... and that is confusing me. If you are using HTTPAPI, you aren't writing a CGI program that runs under the IBM HTTP server, are you?

Or does it do both act as both a provider and a consumer?
jarhead0311
Posts: 8
Joined: Wed Dec 21, 2022 4:32 pm

Re: Is getenv('REQUEST_URI') required?

Post by jarhead0311 »

Hi Scott. Maybe I'm confused as to what a CGI program is. This is new to me. I was able to get the QtmhWrStout to send the data to the endpoint in Postman, but when I hardcode the endpoint in the program it did not send the data to the logic app. I'm thinking it's because I'm executing a POST to the logic app and my quess is, that QtmhWrStout doesn't allow to specify the type?

When I changed it to send using HTTPAPI, it worked. That code is below:

Code: Select all

       dcl-proc json_save;

         data = 'status: 200 OK' + x'25' +
                'Content-type:  text/json' + x'25' +
                 x'25' +  yajl_copyBufStr();

         monitor;
           response = http_string('POST': uri: data: 'text/json');
         on-error;
           errorMsg = http_error();
         endmon;

         yajl_genClose();

       end-proc;                    
I've tried everything I can think of, and have looked at the IBM manual and still haven't got the right combination. I'm guessing to execute a POST, I need to use HTTPAPI. Is that correct?

I'm just not sure what questions to ask or what to show to get the answer.
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: Is getenv('REQUEST_URI') required?

Post by Scott Klement »

There are two sides to it...

the "consumer", is the caller -- it is typically an application that needs the API to do some work for it. It makes a request to the API by "calling a URL" (or connecting to an endpoint) and sending it a JSON document (or various other document types depending on the API) containing the details of it's request, and waiting for a response from the API.

The "provider", is the API itself. It runs on an HTTP server and reads requests from the consumers and does some work for them, and provides an answer.

You need to start by knowing which side of the API you are working on. The QtmhWrStout() API that you mentioned is something that the provider side would use. A provider designed to be a CGI program under Apache would work by calling QrmhRdStin to get the input document, getenv('REQUEST_URI') to get the URL, and getenv('REQUEST_METHOD') to get the request method. If the document is JSON, it may use YAJL or a similar tool to interpret it. It would use these inputs to do whatever service the API provides, and would then generate a response (possibly also with YAJL) and use QtmhWrStout to write the response back.

The consumer would generate a document (using YAJL or similar) and a tool like HTTPAPI (or various similar tools) to send the request and receive the response... then use YAJL (or similar) to interpret the response.

You seem to be trying to do them both at the same time. You discuss using QtmhWrStout (though, you did not include it in your code sample.) And you are adding CGI headers to your data (which a consumer would never do)... these are things a provider would do. But then you're calling HTTPAPI, which a consumer would do.
Post Reply