Re: YAJL JSON data - how and when to save?

Scott Klement <[email protected]>
Newsgroups gmane.comp.systems.as400.web
Message-ID <[email protected]>
Hi Dave,

I would typically create an environment variable.  These work great for 
CGI programs because you can set them in the Apache httpd.conf file, and 
they can be set separately for different <Directory>, <Location>, etc 
containers as needed.

So for example, I might do something like this:

ScriptAlias /apitest /QSYS.LIB/SKTESTAPI.LIB/MYPGM.PGM

<Directory /QSYS.LIB/SKTESTAPI.LIB>
   Require all granted
   SetEnv API_LOG_FILE /var/apitest/requestData.txt
   SetEnv QIBM_CGI_LIBRARY_LIST "TESTDB;SKUTILS"
</Directory>

The important part is API_LOG_FILE -- in this example, programs in the 
SKTESTAPI library will log their data to the 
/var/apitest/requestData.txt file.   If API_LOG_FILE isn't defined for a 
program, it would be in "production" mode and wouldn't log anything.

Then in the program I would do something like this:

dcl-pr getenv pointer EXTPROC('getenv');
   name pointer value options(*STRING);
end-pr;

dcl-s logFile varchar(2048);
dcl-s ptr pointer;
dcl-s log int(10) inz(-1);
  :
  :
ptr = getenv('API_LOG_FILE');
if ptr = *null;
   // no log needed
else;
   logFile = %str(ptr);
   log = open( logFile
             : O_CREAT + O_TRUNC + O_INHERITMODE + O_WRONLY
               + O_TEXTDATA + O_TEXT_CREAT + O_CCSID
             : 0
             : 1208
             : 0);
endif;

I included the prototype for "getenv" (get environment variable) in case 
you didn't already have it.  Typically, I'd have this in a copybook or 
similar.

As always, in computer programming, there are many ways to accomplish 
the same thing, but this way has always worked nicely for me.  It's much 
more versatile than something like a data area because it can be defined 
in different places with different values in your httpd.conf

Good luck!


On 1/10/2022 11:40 AM, Dave wrote:
> Hi,
>
>
>
> At the moment, during testing, each time my CGI programme receives JSON
> data, I'm saving it to the IFS.
>
>
> As I won't need to keep the JSON data once the application is deployed, what
> would be the best way to dynamically turn on and off the save function of
> the program in case it were needed? Seems to me there are many ways of
> doing it. I could configure an environment variable, an URL,  change a data
> area, etc. What do you people do ?
>
>
>
>
> Thanks !
-- 
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/web400
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/web400.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.