How to Develop Apps based on a Stubbed Service

The Quantum Fabric Stub back-end response capability helps app developers to continue to develop apps when the backend services that an app connects to are not ready to be leveraged. There are several instances in an app development life-cycle when back-end systems and app development happen in parallel and only the contract or interface for the app to communicate to a backend is finalized. In this scenario, the app developer can create a response template to "stub" the response that is expected from the actual backend. The response template can have data from service requests, hard-coded values or use pre-built functions such as concat, firstName, lastName, gender, random, email, and phone, and options to randomize the output within the required criteria.

For example, in the scenario mentioned earlier, a Quantum app developer can create the service that points to an endpoint URL along with a stub template. The stub response template can be set for each operation of a service. The app developers can continue to develop apps based on a sample back-end response from the stub template. The service can be modified to connect to the configured backend URL or to send a stub response based on a setting.

NOTE: Stubbing is supported only for JSON, XML, and SOAP Integration services.

IMPORTANT: Services built with Stub Backend Response will give mock data and live data as these services can be switch between live backend and mock data.

NOTE: nd response is used by the Data Panel feature of Quantum Visualizer V8 SP3 GA. For more information on Data Panel, click here.

Stub Template

The back-end stubbed response specifies a Stub template for stubbing and returning dynamically-generated mock data, instead of connecting to the back end and getting the data from the back-end URL.

The following table details a sample Stub response template and a back-end response that is generated based on the stub template.

Sample Stub Template

Sample Stub Response
 [
  '{{repeat(1,2)}}',
  {
    "locationID": "{{index()}}",
    "company": "{{toUpperCase(company())}}",
    "phone": "+1 {{phone()}}",
    "address": "{{integer(100, 999)}} {{street()}}, {{city()}}, {{state()}}, {{integer(100, 10000)}}",
    "latitude": "{{float(-90.000001, 90)}}",
    "longitude": "{{float(-180.000001, 180)}}",
    "office":"{{random("HR Head Office","Sales Head Office","Marketing Head Office","Development Center")}}"
  }
]
  [{
        "locationID": "0",
        "company": "RODEOMAD",
        "phone": "+1 371-222-9269",
        "address": "671 Division Place, Grill, South Dakota, 9220",
        "latitude": "-0.29528046",
        "longitude": "159.72824",
        "office": "Marketing Head Office"
    },
{ "locationID": "1", "company": "ACME", "phone": "+1 311-324-8984", "address": "257 Adam Place, McCoy, South Carolina, 21245", "latitude": "-0.23528046", "longitude": "124.72824", "office": "Sales Head Office" }]

Pre-built Functions Supported in Stub Template

The following list of the sample pre-built functions are supported in the Stub response template:

 

 

 

 

 

How to Enable Stub Back-end Response

  1. In the Integration > Operations > Advance section, select the Stub Backend Response check box. The text box is enabled with a sample Stub response template.

  2. Configure your stub template in the provided field.
  3. Click Test. Quantum Fabric generates the backend response based on the Stub template.
  4. Publish the app. After you publish the app, you can test the stub response by either using Admin Console, a client application, or Quantum Fabric.

How to Test a Stub Response from Admin Console

  1. Publish your app to a runtime server.
  2. Go to the runtime server in Admin Console.
  3. Go to the Integration Services tab.
  4. For the stub service that you created, select the stubbed operation from the Operations list.
  5. Click Get Response.

    NOTE: The X-Kony-Stub-Response header as true in the back-end response indicates that the response is generated from the Stub template, and not from the actual back end.

Advanced Parameters in Stub Response

How to Configure a Request Input and Request Header Parameters in Stub Template

You can access input parameters in a Stub template by using the {{requestBody("<request_param_name>")}} function. Additionally, you can access headers by using the {{requestHeader("<header_name>")}} function.

For example, you want to send the testUser request input parameter to the Stub template and the value of the parameter is defined in the Input Parameters section of Console. You can access the input parameter in the stub template as "inputtest": "{{requestBody("testUser")}}".

The following sample Stub template has been configured with the testUser request input parameter.

 [
  '{{repeat(30,40)}}',
  {
    "locationID": "{{index()}}",
    "company": "{{toUpperCase(company())}}",
    "phone": "+1 {{phone()}}",
    "address": "{{integer(100, 999)}} {{street()}}, {{city()}}, {{state()}}, {{integer(100, 10000)}}",
   "inputtest": "{{requestBody("testUser")}}", "latitude": "{{float(-90.000001, 90)}}",
"longitude": "{{float(-180.000001, 180)}}", "office":"{{random("HR Head Office","Sales Head Office","Marketing Head Office","Development Center")}}" } ]

NOTE: Quantum functions for request input and header are as follows:

-  To access any header with name, requestHeader: Syntax: {{requestHeader("<header_name>")}}
-  To access a request parameter, requestBody: Syntax: {{requestBody("<request_param_name>")}}

How to Configure X-Kony-Stub-Request Header

At runtime, when the actual back-end service is available, and you still want to test the Stub response, you can enable the Stub response feature by sending the X-Kony-Stub-Request header parameter as request input.

IMPORTANT: For example, You have created a Stub response, but have not selected the Stub Backend Response check box, and published the back-end app. When you send the X-Kony-Stub-Request header parameter in the request input, even if the stub back response is set to false, you still get the Stub response.

NOTE: You can send headers with values in the SDKs for service level. For example, var headers = {"your-header-keys" : "your-header-values"};

For more information on how to configure headers in SDKs, refer Quantum Visualizer SDKs > Invoking an Integration Service

How to Configure a Global Request Parameter to enable Stubbing from an Application

If you want to enable stubbed response from all services in an app, even if the service is not published with stubbing enabled, you can do so by using the setGlobalRequestParam feature from Quantum Fabric SDK.

Consider a scenario where you want to switch between live and stubbed services during app development and you have an option from the app to switch between services. Here, this feature helps you to effectively troubleshoot in case there is any issue with the back-end service data or with the application code.

Syntax:

 setGlobalRequestParam(paramName, paramValue, aramType);

For more information on Global Request Parameter - SDKs, refer Quantum Visualizer SDKs > Initializing the Quantum Client SDK > setGlobalRequestParam, and search for setGlobalRequestParam.

How to Disable Stubbing in an Environment

When you want to use a back-end service at all times and want to disable the Stub response feature at the environment-level (such as production environment) to avoid Stub response in a non-development environment, you can set the KONY_SERVER_DISABLE_ALL_STUB_RESPONSE configuration property with the value as true (default value is false) as -D param or in the server_configuration table of the Admin database.