Page History
...
Using the GetDatabaseItems Service
We previously introduced the GetDatabaseItem service. There is a similar service called GetDatabaseItems and it is also a member of the HTTP_Resource_Services module. Like the GetDatabaseItem service, the GetDatabaseItems service is deprecated but we do not intend to remove it. For certain use cases it is quite handy for producing collection resources with embedded content:
Code Block | ||
---|---|---|
| ||
API customers.GET jsonResource = HTTP_Resource_Services('GetDatabaseItems', '', 'CUSTOMERS', FullEndpointURL, 'FIRST_NAME' : @FM : 'LAST_NAME', 'firstName' : @FM : 'lastName') If Error_Services('NoError') then // Set the response body with the serialized JSON object and set the Content-Type response header. HTTP_Services('SetResponseBody', jsonResource, False$, 'application/hal+json') end else // There is an error condition so call the SetResponseError service. HTTP_Services('SetResponseError', '', '', 500, Error_Services('GetMessage'), FullEndpointURL) end end api |
This approach doesn't provide a way to custom label the embedded resource. As shown below, embedded resources are labelled as item. Nevertheless, this service allows the number of the lines of code to be reduced so it might be more convenient to use.
Code Block | ||
---|---|---|
| ||
{
"_embedded":{
"item":[
{
"firstName":"Harrison",
"lastName":"Haufler",
"_links":{
"self":{
"href":"https://www.examples.org/api/customers/266"
}
}
},
{
"firstName":"Haydee",
"lastName":"Denooyer",
"_links":{
"self":{
"href":"https://www.examples.org/api/customers/271"
}
}
},
{
"firstName":"Heike",
"lastName":"Berganza",
"_links":{
"self":{
"href":"https://www.examples.org/api/customers/254"
}
}
},
{
"firstName":"Helga",
"lastName":"Fredicks",
"_links":{
"self":{
"href":"https://www.examples.org/api/customers/202"
}
}
},
{
"firstName":"Herman",
"lastName":"Demesa",
"_links":{
"self":{
"href":"https://www.examples.org/api/customers/125"
}
}
},
{
"firstName":"Herminia",
"lastName":"Nicolozakes",
"_links":{
"self":{
"href":"https://www.examples.org/api/customers/287"
}
}
},
{
"firstName":"Hillary",
"lastName":"Skulski",
"_links":{
"self":{
"href":"https://www.examples.org/api/customers/186"
}
}
},
{
"firstName":"Howard",
"lastName":"Paulas",
"_links":{
"self":{
"href":"https://www.examples.org/api/customers/132"
}
}
}
]
},
"_links":{
"self":{
"href":"https://www.examples.org/api/customers"
}
}
} |