Just use Rainer Ross' Open Source Tool WebSrvUtl -
https://github.com/RainerRoss/WEBSRVUTL.
Here a (running) example by using Rainer's Functions.
The hardest part is to generate the JSON document (with SQL):
CTL-Opt BndDir('HSBNDDIR05': 'YAJL': 'WEBSRVUTL')
DecEdit('0.') Option(*NoDebugIO: *NoUnRef) Alloc(*TeraSpace)
Main(WEBJSON01);
/If Defined (*CRTBNDRPG)
Ctl-Opt ActGrp('WEBJSON01');
/EndIf
//*******************************************************************************************
/Include WebSrvUtl/QCPYSRC,WEBSRVUTL
/Include WebSrvUtl/QCPYSRC,APIERR
//*******************************************************************************************
DCL-S GblJSONData SQLType(CLOB: 1000000) CCSID(1208);
//URL-Key Information
DCL-DS GblDSUrlKey Qualified Inz;
CustNo VarChar(15);
SalesYear Packed(4);
End-DS;
//Program Status Data Strucutre
DCL-DS PGMSDS PSDS Qualified;
MsgTxt Char(80) Pos(91);
MsgTxtShort Char(50) Pos(91);
End-Ds;
//*******************************************************************************************
Exec SQL Set Option Commit=*None, DatFmt=*ISO, TimFmt=*ISO,
DecmPt=*Period, CloSQLCsr=*EndActGrp, UsrPrf=*Owner;
//*******************************************************************************************
// WEBJSON01: Main Procedure
//*******************************************************************************************
DCL-Proc WEBJSON01;
DCL-S LocHeader like(GblHeader); // HTTP-Header
DCL-S LocErrMsg VarChar(132);
//-------------------------------------------------------------------------------------------
Monitor;
Clear GblDSUrlKey; // URL Key Values
Clear GblJSONData; // JSON Data
LocHeader = getHeader(); // Get HTTP-Header
getInput(); // Get Input
GblDSUrlKey.CustNo = %Trim(getKeyValue('Kunde')); // Customer No
Monitor;
GblDSUrlKey.SalesYear = %Dec(getKeyValue('SalesYear'): 4: 0); // Sales Year
If GblDSURLKey.SalesYear < %SubDt(%Date(): *Years) - 10;
Clear GblDSURLKey.SalesYear;
EndIf;
On-Error;
Clear GblDSURLKey.SalesYear;
EndMon;
exec sql
With x as (Select Year(SalesDate) SalesYear, CustNo,
Sum(Amount) Sales,
Cast(Avg(Amount) as Dec(11, 2)) Average
From HSRRRPG.SalesX
Where CustNo = case When :GblDSUrlKey.CustNo > ''
Then :GblDSUrlKey.CustNo
Else CustNo End
and Year(SalesDate)
= Case When :GblDSUrlKey.SalesYear > 0
Then :GblDSUrlKey.SalesYear
Else Year(SalesDate) End
Group By Year(SalesDate), CustNo)
Select JSON_Object('JahresUmsatz':
JSON_ArrayAgg(
JSON_Object('Jahr' : SalesYear,
'Kunde' : Trim(CustNo),
'Umsatz' : Sales,
'Durchschnitt': Average)
Order By SalesYear, CustNo))
into :GblJSONData
From x;
If SQLCODE < *Zeros;
Exec SQL Get Diagnostics Condition 1 :LocErrmsg=MESSAGE_TEXT;
Exec SQL Set :GblJSONData = JSON_Object('Error': :LocErrMsg);
EndIf;
WrtStdout(%Addr(LocHeader:*Data): %Len(LocHeader): DsApierr);
if GblJSONData_Len = *Zeros;
Exec SQL Set :GblJSONData = Json_Object('Error':
'No Data found');
endif;
WrtStdout(%Addr(GblJSONData_Data): GblJSONData_Len: DsApierr);
On-Error;
EndMon;
end-proc;
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them and keeping them!"
„Train people well enough so they can leave, treat them well enough so they don't want to.“ (Richard Branson)
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxx> On Behalf Of Booth Martin
Sent: Donnerstag, 9. August 2018 19:15
To: RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>
Subject: Web service for dummies?
This has to be simpler than I am making it. I have a web page ( louie.martinvt.com ) that presents a simple page of states and cities. It is populated with a .json file located with the page.
The actual .json file is produced with an RPGLE program (using Scott's
YAJL) and a regular physical file. My intention is to have an RPG web service provide that .json file and it be accepted by my web page's javascript. I have used Scott's program for that but I am missing something.
So far, all of the articles & examples I find discuss solutions requiring php, jquery, or some other ancillary product.
I have looked for a simple "Hello World" solution that goes end-to-end and had no luck.
Any examples or tutorials that are dumbed way down, so I can at least see what it is I am supposed to be doing?
--
Booth Martin
www.martinvt.com
(870)576-9371
(802)461-5349
Hidden talent counts for nothing. -- Nero
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD
As an Amazon Associate we earn from qualifying purchases.