Resource request from hybrid client applicationsimprove this page | report issue
MobileFirst applications can access resources using the
WLResourceRequest REST API.
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.
This tutorial explains how to use the
WLResourceRequest API with an HTTP adapter.
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 method 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 the
sendFormParameters(json) method instead. This method converts the JSON to a URL encoded string, sets the content-type to
application/x-www-form-urlencoded, and sets 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 MobileFirst project.
The sample uses the HTTP adapter created in the HTTP Adapter tutorial.
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.