Invoking adapter procedures from hybrid client applications
MobileFirst applications can adapt procedures to communicate with any data source. This tutorial explains how to use the REST API for returning data from an HTTP adapter. The same can be applied using other data sources (such as SQL adapters, etc).
The REST API works with all adapters and external resources, and is supported in the following hybrid environments: iOS, Android, Windows Phone 8, and Windows 8.
If your application supports other hybrid environments such as BlackBerry, Mobile Web, or Desktop Browser, see the tutorial for MobileFirst 6.3.
WLResourceRequest class handles resource requests to MobileFirst adapters or external resources.
The parameters for the constructor are:
- request URL: To access an adapter within the same project, the URL should be
To access resources outside of the project, use the full URL.
- HTTP method: Most commonly
- timeout: optional, request timeout in milliseconds
By using the
setQueryParameter method, you can include query (URL) parameters in the REST request.
- In Java adapters or external resources, use
setQueryParameterfor each parameter.
send() method triggers the request.
send takes an optional parameter to set a body to the HTTP request, which could be a JSON object or a simple string.
To send URL encoded form parameters, use
sendFormParameters(json) instead. It will convert the JSON to a URL encoded string, set the content-type to
application/x-www-form-urlencoded, and set it as the HTTP body.
For more information about
WLResourceRequest, see the API reference in the user documentation.
onFailure callbacks receive a
response object, which typically contains the following properties:
status: The HTTP response status
responseJSON: An object that contains the data that is returned by the invoked procedure, and additional information about the procedure invocation.
The object is returned to a corresponding success/failure handler.
warningsare optional arrays of strings that contain messages.
isSuccessfulproperty is set to
trueif the procedure invocation succeeded (even if no data was retrieved), or to
- The response can contain other metadata such as
Handling the result
The rest of the invocation result depends on what was retrieved from the back-end system. In this example, the
Items element is a JSON representation of the XML code that was received from the back end, after the rules in the XSL file were applied.
Click to download the Studio project.
The sample uses the HTTP adapter created in the HTTP Adapter tutorial.