× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks Brad. It looks like you are pointing me to Apache which is where I figured I would end up based on the walls that I kept running into.

Now the next question is can you point me to a good resource on setting up Apache? You provided the config for the server but I have no idea where that goes. When I looked at Apache config, many of the sites that I found assume that I knew things that I don't and consequently I was missing a key piece that caused me to fail. I really need the "Apache config for dummies" book.

Us newbies are such a pain sometimes. 😊

As for the SQL, yes, there will definitely be safeguards in place. I just didn’t figure it was worth the details but I appreciate your callout just in case I didn't know better. I also learned years ago to protect the SQL so that someone doesn't enter a screen value such as "somevalue';delete from itemtable" to cause a multiple step statement such as

update mytable set myfield = 'somevalue';delete from itemtable; <= If you happen to have an itemtable, it is now empty.


-----Original Message-----
From: WEB400 <web400-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Brad Stone
Sent: Saturday, October 8, 2022 9:43 AM
To: Web Enabling the IBM i (AS/400 and iSeries) <web400@xxxxxxxxxxxxxxxxxx>
Subject: Re: [WEB400] Creating a REST API with RPGLE

I would suggest outputting JSON as it's more generic and most applications can read it.

Here's a simple program and HTTP config that will do what you want using RPG and YAJL.. you just need to change the $Data subroutine to run your SQL statement, then build the JSON as it reads the results from the command:

https://fieldexit.com/forum/display?threadid=522

PS, passing in straight SQL can be very dangerous in the wrong hands, so I would put some sort of checking so there's not something like delete from lib.file passed in.

On Fri, Oct 7, 2022 at 8:09 PM <smith5646midrange@xxxxxxxxx> wrote:

First, let me say I am trying to do something here that I have zilch
experience with from the IBM i perspective. I have done this type of
stuff using C#.Net on Windows but nothing on the IBM i. Yesterday was
my first voyage into IBM Web Administration for i.

That said, I am trying to create a REST API written in RPGLE that will
return JSON data. I have looked at a lot of examples but just can't
find what I am after.

This needs to be modeled after some existing C#.Net REST APIs so the
following requirements are not negotiable.

The request needs to be a POST type.
The body of the POST request needs to have two "fields".
1) Input - An SQL statement that will be used to retrieve the data.
2) Output - The results of the SQL. These results can be anything
so the fields can't be predefined in the RPGLE program's parameters
like they are in all of the examples that I find. There can also be
multiple records so it would end up having an array in the results. I
think I need a single "results" field that is pretty big and I will
need to manually build the JSON for it.

I tried creating a new HTTP server and deploying a service to it. I
have been successful using Scott's customer lookup as a model and I
have been able to do a few different things to experiment. However, I
can't figure out how to handle the POST body for input or the array
results in the output.

One attempt was to create the following:
dcl-pi *n;
sql char(5000);
resultSet char(50000);
end-pi;
The problem was that I got back a value in the resultSet that was
really junked up JSON because it escaped all of the " as \". I
considered trying to make the resultSet value return as plain text
instead of JSON (I'm assuming I can do that somehow) but I decided
before I went too far down the wrong rabbit hole, I would ask for
help.

Can someone help point me in a good direction? I don't mind doing a
lot of web digging, I just don't really know what I need to search for
to do the digging.

Thanks.


--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400)
mailing list To post a message email: WEB400@xxxxxxxxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxxxxxxxx Before posting, please
take a moment to review the archives at
https://archive.midrange.com/web400.


--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list To post a message email: WEB400@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxxxxxxxx Before posting, please take a moment to review the archives at https://archive.midrange.com/web400.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.