Using Mock ReST APIs

improve this page | report issue

Mock API

While developing a mobile app, usually the actual backend from where the data needs to be fetched would not be readily available to the mobile developers. In those cases it would be helpful if a mock server is available which returns the same data as the actual backend. Mock API feature in Digital App Builder helps in this regard. The mobile app developer can easily mock the server by just providing a JSON data.

Note: This feature is available only in Code mode.

To create and manage APIs to mock backend REST services:

  1. Open your app project in Code mode
  2. Select API. Click Add an API. Mock API

  3. In the window that opens, enter a name for your API and click Add. Mock API add

  4. This will show the created API with the autogenerated URL. Mock API jason

  5. Click Edit. Provide the data which you wanted to return on the invoking this API and click Save. For example,

         "firstName": "John",
         "lastName": "Doe",
         "title": "Director of Marketing",
         "office": "D531"
         "firstName": "Don",
         "lastName": "Joe",
         "title": "Vice President,Sales",
         "office": "B2600"

    Mock API jason sample

Note: To quickly test the API, Click Try now and it will open the swagger documentation in your default browser where you can test your APIs.

Consuming the Mock APIs in the app

  1. In the code mode, drag-and-drop the API Call code snippet from MOBILE CORE section.
  2. Edit the code to modify the URL and point to the Mock API endpoint. For example,

      var resourceRequest = new WLResourceRequest(
          { "useAPIProxy": false }
          function(response) {
              alert("Success: " + response.responseText);
          function(response) {
              alert("Failure: " + JSON.stringify(response));
Last modified on December 20, 2019