For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.


Client access to adapters

Mobile clients can access both Javaâ„¢ and JavaScript adapters from the /adapters endpoint on the server.

The URL pattern for accessing the /adapters endpoint is as follows:

http(s)://<server>:<port>/<Context>/api/adapters/<adapter-name>/*

For example, assuming that http://mfp-server-host/project is the IBM MobileFirstâ„¢ Platform Foundation project URL, and the project contains one Java adapter named adapter1 and the adapter has a resource with path /res1, then /res1 is accessible from the following URL:

http://mfp-server-host/project/api/adapters/adapter1/res1

Note: Using the /adapters endpoint is the recommended way to access IBM MobileFirst Platform Foundation adapters. This endpoint supports both JavaScript and Java adapters and is protected by an OAuth security mechanism.


Accessing adapters from a mobile client

IBM MobileFirst Platform Foundation provides a client API for accessing OAuth protected resources such as adapters. If you choose to use MobileFirst client for that purpose, it will automatically handle security for you. The following examples demonstrate how to use the client API to access an adapter resource:

Cordova JavaScript client

var request = new WLResourceRequest("adapters/adapter1/res1", WLResourceRequest.GET); request.send().then( function(response) { alert(JSON.stringify(response)); }, function(error) { alert(JSON.stringify(error)); } );

Native Android client

WLResourceRequest req = new WLResourceRequest(new URI("adapters/adapter1/res1"), WLResourceRequest.GET); req.send(new WLResponseListener(){ @Override public void onSuccess(WLResponse response) { // handle success } @Override public void onFailure(WLFailResponse response) { // handle failure }});

Native iOS client

NSString static *const RESOURCE_URL = @"adapters/adapter1/res1"; WLResourceRequest *request = [WLResourceRequest requestWithURL:[NSURL URLWithString:RESOURCE_URL] method:WLHttpMethodGet]; [request sendWithCompletionHandler:^(WLResponse *response, NSError *error) { NSString *httpStatus = [NSString stringWithFormat:@"%d", [response status]]; self.httpStatusTextField.text = httpStatus; if (error != nil) { [self updateView:[error description]]; } else { [self updateView:[response responseText]]; } }];

Native Windows 10 UWP and Windows 8 Universal

WLResourceRequest req = new WLResourceRequest("adapters/adapter1/res1", WLResourceRequest.GET); InvokeListener listener = new InvokeListener(); req.send(listener); public class InvokeListener : WLResponseListener { public void onSuccess(WLResponse response){ //handle success } public void onFailure(WLFailResponse response){ //handle failure } }


RESTful access to Java adapters

You call an existing Java adapter over HTTP via REST URLs.

The URL pattern is as follows:

http(s)://<server>:<port>/<Context>/adapters/<adapter-name>/*

For example:

http://<hostname>:<port>/mfp/adapters/TodaysNews/getStory?story=world

Java adapters support all REST features, so we can use all HTTP request methods, headers, query parameters, and more.


RESTful access to JavaScript adapters

You call existing JavaScript adapter procedures over HTTP via REST URLs.

The URL pattern is as follows:

http(s)://<server>:<port>/<Context>/api/adapters/<adapter-name>/<procedure-name>

For example:

http://<hostname>:<port>/mfp/api/adapters/TodaysNews/getStories?params=['world']

Both the GET and POST methods can be used to call the adapter procedure. The procedure arguments are passed as the value of a parameter called params. This parameter is a query parameter for GET requests and a form parameter for POST requests. The value must be a JSON array of parameters that are provided in order.

Note: For successful invocations, the status code of the HTTP response is set to 200 (OK). The response body contains the JSON output that resulted from the invocation of the JavaScript adapter. If an error occurred during adapter invocation, the status code is set to 500 (Internal Server Error).

Parent topic: Developing the server side of a MobileFirst application