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


JavaScript server-side API

JavaScript adapters can use the IBM MobileFirst™ Platform Server JavaScript API to perform server-related operations such as: calling other adapters, logging adapter activity, getting values of configuration properties, reporting activities to IBM MobileFirst Analytics, and getting the identity of the request issuer.


MFP.Server and MFP.Logger

The JavaScript server-side API is provided in two classes:

Examples of the use of the API are provided in the following sections.

Security
The MFP.Server.getTokenIntrospectionData function provides access to the security context of the client and the client registration data. The following sample uses the function to get the display name of the authenticated user:

AuthenticatedUser user = securityContext.getAuthenticatedUser(); return "Hello " + user.getDisplayName(); }

Calling adapter procedures
The MFP.Server.invokeProcedure makes it easy to perform requests to other adapters in the same server.

The following example shows how to use this function to call a JavaScript adapter:

function callAnotherProcedure() { var invocationData = { adapter : “JsAdapter”, procedure : “getStories” }; return MFP.Server.invokeProcedure();} For more information, see Configuring adapters.

Configuration properties
The MFP.Server.getPropertyValue function enables the adapter to read a property from the adapter configuration.

For example, assume you have a user-defined property, databaseName. To get its value, you could write the following code:

var dbName = MFP.Server.getPropertyValue(‘databaseName’); For more information, see Configuring adapters.

Analytics
The MFP.Server.logActivity function reports information to IBM MobileFirst Analytics.

For example, to send the string Getting account balance, you might write:

function getBalance(user) { MFP.Server.logActivity(‘Getting account balance); // perform operation }

Logging
The JavaScript API provides logging capabilities through the MFP.Logger class. It contains four functions that correspond to four standard logging levels.

Parent topic: Developing JavaScript adapter code