-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsimpleREST.rpgle
62 lines (43 loc) · 1.51 KB
/
simpleREST.rpgle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<%@ language="RPGLE" %>
<%
**free
ctl-opt copyright('System & Method (C), 2019');
ctl-opt decEdit('0,') datEdit(*YMD.) main(main);
/* -----------------------------------------------------------------------------
Simple REST - showcase that injection is not possible
A list of product prduced by a given manufacturer
Run from the browser:
http://sandbox.icebreak.org:60060/simpleRest?manuid=SONY
http://my_ibm_i:60060/simpleRest?manuid=SONY
Compile:
CRTICEPGM STMF('/www/IceBreak-Samples/simpleREST.rpgle') SVRID(samples)
By Date PTF Description
------ ---------- ------- ---------------------------------------------------
NLI 22.06.2019 New program
----------------------------------------------------------------------------- */
/include noxDB
/include qasphdr,iceUtility
dcl-proc main;
dcl-s manuId varchar(30);
dcl-s sqlStr varchar(1024);
dcl-s pResult pointer;
// We will produce JSON in UTF-8 format
setContentType('application/json;charset=UTF-8');
// Get the manufaturer from the query string or the form
manuId = reqStr('manuId');
// Create the dynamic sql statement
// Note: strQuot to protect agains SQL-injections
sqlStr = (`
select *
from icproduct
where manuId = ${ strQuot(manuId)}
order by Desc
`);
// run the sql and return a JSON object graph in memory
pResult = json_sqlResultSet (
sqlStr
);
// serializet it to the client and dispose memory
responseWriteJson(pResult);
json_delete(pResult);
end-proc;