With IBM MobileFirst™ Platform Foundation,
you can create, test, and deploy adapters that are written in JavaScript.
Benefits of MobileFirst JavaScript adapters
In
addition to benefits that adapters provide in general, JavaScript adapters also provide these:
- Fast development: Adapters are developed
in JavaScript and XSL.
Developers employ flexible and powerful server-side JavaScript to produce succinct and readable
code for integrating with back-end applications and processing data.
Developers can also use XSL to transform hierarchical back-end data
to JSON.
- REST Interface: With the REST interface,
you can benefit from the OAuth 2.0 security framework. For more information,
see Client access to adapters.
JavaScript adapter
types
IBM MobileFirst Platform Foundation V8.0.0
supports HTTP and SQL adapters:
- With a HTTP adapter, you can send GET or POST HTTP requests and
retrieve data from the response headers and body. HTTP adapters work
with RESTful and SOAP-based services, and can read structured HTTP
sources such as RSS feeds.
- With an SQL adapter, you can communicate with any SQL data source.
You can use plain SQL queries or stored procedures.
The JavaScript adapter framework
The
adapter framework mediates between the mobile apps and the enterprise.
A typical flow is depicted in the following diagram.
- The connectivity and auto-conversions are facilities that are
provided with IBM MobileFirst Platform Foundation.
- The back-end application, JavaScript code
and XSLT components in the MobileFirst Server are
supplied by the adapter or app developer.
Figure 1. The JavaScript adapter
framework
- An adapter provides a set of services, called procedures. Mobile
apps invoke procedures by issuing Ajax requests.
- The procedure retrieves information from the back-end application.
- The back-end application then returns data in some format:
- If this format is JSON, the MobileFirst Server keeps
the data intact.
- If this format is not JSON, the MobileFirst Server automatically
converts it to JSON. Alternatively, you can provide an XSL transformation
(XSLT) to convert the data to JSON. In this case, the returned content
type from the back end must be XML. Then, you can use an XSLT to filter
the data.
- The JavaScript implementation
of the procedure receives the JSON data, performs any additional processing,
and returns it to the calling app.
Note: - Writing an adapter that pulls large amounts of data and transfers
it to the client application is discouraged because the data must
be processed twice: once at the adapter and once again at the client
application.
- HTTP POST requests are used for client-server communications between
the MobileFirst application
and the MobileFirst Server.
Parameters must be supplied in a plain text or numeric format. To
transfer images (or any other type of file data), they must first
be encoded in Base64 format.