It is possible to create any complex response using aperïo, but there are couple of limitations:
The response is prepared in job memory which is limited to 16MB per job. These 16 MB are total available memory limited by IBM in single cheap storage model. This is more than enough if someone wants to create web services in micro service style. Iptor approach is performance and micro services structure of API. That is why we stick to straight requests/responses. Every time when RPG program is created the programmer must to take it into consideration, that job memory is limited. The other factor is reasonable response time. It may happen that creating verry complex and big response takes long time.
Aperio has predefined structure request and response. It means the response data is ALWAYS put into “data” object in JSON…
old protocol:
{
"IptorAPI":"1.0",
"data":{">>here is place for Your response<<"},
"id":"js069cty"
}
New protocol
{
"data":{">>here is place for Your response<<"}
}
There are at least three ways to create complex response:
In QSAMPLES source file there are two examples how to build complex response:
program EXAMPLE012 creates following response:
{
"IptorAPI":"1.0",
"data":{
"itemCodes":[
"11991-ABC",
"11992-CDE",
"11993-FGH"
],
"alternates":[
"11991",
"11992",
"11993"
],
"itemTypes":[
"A",
"B",
"C"
],
"dates":[
"2019-02-22",
"2019-02-23",
"2019-02-24"
],
"flags":[
true,
false
],
"onHands":[
0,
0,
0
],
"details":[
{
"det01":"ABC",
"det02":123
},
{
"det01":"DEF",
"det02":456
},
{
"det01":"GHI",
"det02":789
}
],
"details2":[
{
"det201":"YYYY",
"det202":1234,
"det203":99,
"sub-details2":[
{
"det2201":"aaaa",
"det2202":1234
},
{
"det2201":"bbbb",
"det2202":5678
}
]
},
{
"det201":"ZZZZ",
"det202":5678,
"det203":88,
"sub-details2":[
{
"det2201":"cccc",
"det2202":7777
},
{
"det2201":"dddd",
"det2202":8888
}
]
}
]
},
"id":"jxedanwt"
}
program EXAMPLE013 creates following response:
{
"IptorAPI":"1.0",
"data":{
"myJSON":{
"field1":"ABC",
"field2":"DEF",
"field3":123,
"field4":456,
"sub-object":{
"field3":"ABC",
"field4":"DEF",
"booleanField1":false,
"booleanField2":true,
"nullField":null
},
"sub-array":[
"Value1",
"Value2",
"Value3"
]
}
},
"id":"jxedkugz"
}