Re: Creating a REST API with RPGLE
Nadir Amra <amra-r/[email protected]> Sun, 9 Oct 2022 01:35:43 +0000
| Newsgroups | gmane.comp.systems.as400.web |
|---|---|
| Message-ID | <BN8PR15MB29950C451C5337CCAABC6B17E4219@BN8PR15MB2995.namprd15.prod.outlook.com> |
Have you checked out integrated web services server[1]? Designed to externalize ILE programs/service programs as APIs. Check out the parts 1, 2, 3 of the following articles to get some experience. [1] https://www.ibm.com/support/pages/node/633935 [2] https://developer.ibm.com/tutorials/i-rest-web-services-server1/ --------------------------------------------------- Nadir Amra e-mail: amra-r/[email protected] From: WEB400 <[email protected]> on behalf of [email protected] <[email protected]> Date: Friday, October 7, 2022 at 8:09 PM To: 'Web Enabling the IBM i (AS/400 and iSeries)' <[email protected]> Subject: [EXTERNAL] [WEB400] Creating a REST API with RPGLE 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: [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 . -- 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.