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


Initializing the MobileFirst SDK

Initialize the MobileFirst web SDK before using its APIs to develop your web application.


Before you begin

Download the MobileFirst web SDK and add it to our web application. For more information, see Adding the MobileFirst SDK to web applications.


Overview

Add the initialization code that is described in the following procedure to our application's JavaScript code (for example, in index.js).


Procedure

  1. Define an initialization-properties JSON object that sets the following mandatory SDK initialization properties:

    • mfpContextRoot - the context root of your application's MobileFirst Server runtime.
    • applicationId - a unique identifier for our application.

      Note: The application ID that is set in this initialization option must be the same ID that you provide when your register the application. For more information, see Registering web applications to MobileFirst Server.

    For example, the following code defines an mfpInitProperties variable that sets the context root of MobileFirst Server (mfpContextRoot) to /mfp (the default context root of the MobileFirst Development Server), and sets the application ID (applicationId) to com.example.myapplication:

    var mfpInitProperties = { 'mfpContextRoot' : '/mfp' , 'applicationId' : 'com.example.myapplication' };

  2. Call the WL.Client.init method of the core web-SDK module (ibmmfpf.js) to initialize the SDK. Pass the initialization-properties JSON object that you defined in the previous step (mfpInitProperties) as the parameter of this method. Use a JavaScript promise to implement the initialization-completion logic of the asynchronous init method, as demonstrated in the following example:

    WL.Client.init(mfpInitProperties).then (function(){ console.log('MobileFirst web SDK initialized'); // Application initialization logic });

    Note: For backwards compatibility with Cordova applications that use the same MobileFirst client JavaScript API, we can select to implement the initialization-completion logic in a wlCommonInit function instead of using a JavaScript promise.


What to do next

We can now use the JavaScript client-side API to develop your application and add MobileFirst capabilities. If you selected to add the web-analytics module of the SDK (ibmmfpfanalytics.js), as outlined in Adding the MobileFirst SDK to web applications, use the JavaScript web analytics client-side API to add MobileFirst Analytics features to our application (see Analytics and Logger).

To use server-side features, such as adapters and security, first register your application to a running instance of MobileFirst Server. See Registering web applications to MobileFirst Server.

Parent topic: Developing web applications