Skip to content

How to Develop Apps based on a Stubbed Service

User Guide: Integration > Advanced Configurations > Stub Template (sample code)

How to Develop Apps based on a Stubbed Service

The VoltMX Foundry 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 Volt MX 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 Volt MX Iris 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:

repeat(, )

Descriptionrepeat function repeats JSON or XML objects randomly based on the value range provided in the syntax. This is typically set at the beginning of a collection to repeat number of times as required. For example, it can be set to get a random number of transactions for an account for a set format by setting repeat function at the head of the collection as shown in the default template above.
Syntax'{ {repeat (<lower_value>, <upper_value>)} }'
Sample stub template'{ {repeat(30,40)} }'

repeat(\<number>)

Descriptionrepeat function repeats JSON or XML objects randomly based on the fixed number provided in the syntax. This is typically set at the beginning of a collection to repeat number of times as required. For example, it can be set to get a random number of transactions for an account for a set format by setting repeat function at the head of the collection as shown in the default template above.
Syntax'{ {repeat (<number>)} }'
Sample stub template'{ {repeat(2)} }'

integer(min,max)

DescriptionGenerates a random integer in the specified range. 
Syntax"{ {integer(min,max)} }"
Sample stub template"productRating":"{ {integer(0,5)} }"
Sample stub response"productRating": "4"

float(min,max)

DescriptionGenerates a random 32-bit floating point number in the specified range.
Syntax"{ {float(min,max)} }"
Sample stub template"floatrange": "{ {float(3,9)} }"
Sample stub response"floatrange": "6.718242"

float(min,max,"%.2f")

DescriptionGenerates a random 32-bit floating point number in the specified range of floating point numbers, with an option to round of the number of decimal places.
Syntax"{ {float(min,max,"%.2f")} }"
Sample stub template"floatrange": "{ {float(3,9,"%.2f")} }"
Sample stub response"floatrange": "8.87"

double(min,max)

DescriptionGenerates a random 64-bit double number in the specified range.
Syntax"{ {double(min,max)} }"
Sample stub template"double": "{ {double(2,8)} }"
Sample stub response"double": "7.654668228367652"

long(min,max)

DescriptionGenerates a random long number in the specified range.
Syntax"{ {long(min,max)} }"
Sample stub template"network":"{ {long(200,500)} }"
Sample stub response"network":"378"

uuid()

DescriptionGenerates a random GUID.
Syntax"{ {uuid()} }"
Sample stub template"objects": "{ {uuid()} }"
Sample stub response"objects": "fb81ad08-42e3-4b61-9a2c-636f95952766"

hex()]

DescriptionGenerates a random 16 bytes hexadecimal string.
Syntax"{ {hex()} }"
Sample stub template"color": "{ {hex()} }"
Sample stub response"color": "b53ff7fa4b63b18cdf7729e85c39e660"

hex(size)]

DescriptionGenerates a random hexadecimal string according to the specified size in bytes.
Syntax"{ {hex(size)} }"
Sample stub template"color": "{ {hex(2)} }"
Sample stub response"color": "1b41"

objectId()

DescriptionGenerates a hexadecimal string of size 12 bytes.
Syntax"{ {objectId()} }"
Sample stub template"id": "{ {objectId()} }"
Sample stub response"id": "1c91293a4c777000585e04e6"