Query Transform
The query request transform allows authors to take the uri parameters and modify or add new query parameters to the configuration.url
.
Normally uriParameters configured on the Service Data Provider or the Call Rest action are appended to the URL automatically but there may be cases where user would want to tweak the query parameters some more.
Let's say the endpoint GET /incidents, supports a query parameter called "search", which does a semantic aka contextual search. If there is a special param that needs to always be appended before calling the endpoint, then the transform function could be used for that.
Signature
The paginate transform function can be declared like this:
Request.prototype.query = function(configuration, options, transformsContext) {
var c = configuration;
// use the query criteria provided on 'options' parameter to generate the query param
// update c.url as needed
return c;
}
This function has the following parameters:
configuration
an object with the following properties:- Refer to the signature in Request Transformation Functions for details on the various properties.
options
the uri parameters.transformsContext
is an object that is set by the author (ServiceDataProvider, RestHelper, Call Rest action) to then be passed as is to all transforms for the current fetch cycle.
The function returns the updated configuration
object.
Examples
The examples below illustrate the arguments passed to the query transform as well as the effect its code has on the fetch performed by the RestHelper.
The example below uses a service fixitfast
that has a GET endpoint to retrieve the list of customers.
Example 1-12 ServiceDataProvider variable
Assume that the following variable of type vb/ServiceDataProvider is defined in a page that refers to the GET /incidents endpoint.
The SDP variable includes the uriParameters
property as shown below.
{
"variables": {
"incidentListTableSource": {
"type": "vb/ServiceDataProvider",
"input": "none",
"defaultValue": {
"endpoint": "fixitfast-service/getIncidents",
"keyAttributes": "id",
"uriParameters": {
"technician": "hcr",
"searchIn": "{{ $page.variables.searchType }}"
},
"transforms": {
"request": {
"query": "{{ $page.functions.query }}"
}
}
}
}
}
}
The query
request transforms function uses the criteria passed in via the options
parameter to build a query param on the configuration url.
The query
transform is implemented in the page module JavaScript as follows:
define([], function () {
class PageModule {
query(configuration, options, transformsContext) {
const o = options;
const c = configuration;
if (o && !o.searchIn) {
let newUrl = c.url;
newUrl = `${newUrl}&search=faq`; // appends faq search qp
c.url = newUrl;
}
return c;
}
}
return PageModule;
});