Search Results

Transformation Stage

Transform the incoming payload using JavaScript and Node.js​ ​modules​. The supported payload formats include JSON object or an​ ​XML string.

You can configure different transformation stages for request and response pipelines. To​ ​add​ ​a​​ ​Transformation stage to request pipeline,​ ​select Transform Request when​ ​adding a new stage​. To add a Transformation stage to the response pipeline, select Transform Response when adding a new stage.​

Configurations

Transformation stage contains the following fields:

Field Description
Name Name of Transformation stage.
Description Description of Transformation stage.
JSON input/Input JSON A sample generated from the JSON Schema embedded in the API specification. Microflow® generates the sample based on the JSON Schema and the method type associated with the operation defined in the API specification.
JavaScript payload transformation/JavaScript transformation JavaScript code to process the request. In the request flow, the parameter passed to the custom JavaScript function is payload, which is the payload field of the request object. In the response flow, the parameters passed to the custom JavaScript function are body and done, where body is the response body received from the backend service, and done is the callback function to be invoked by users with processed result, whenever the code finishes its execution. See Custom JavaScript Stage for more information.
JSON output/Output JSON The output of the transformation generated using the JSON input and the JavaScript payload.

Examples

Refer to the following examples to configure Transformation stage.

Example of Request Transformation

The following sample code shows how to add a prefix tibco- to the name field when calling the POST/pet API of the Petstore sample.

var _ = require('lodash');
if (_.isObject(payload)) {
  payload.name = 'tibco-'+payload.name;
}
 done(payload);

After pushing the configured stage, send a POST request to <Microflow endpoint>/pet, for example, https://integration.cloud.tibco.com:98/7sytdyky0xvm6db69fkwdqqqt20i61z/pet with the following data:

{
"id": 0,
"category": {
    "id": 0,
    "name": "string"
},
"name": "doggie",
"photoUrls": ["string"],
"tags": [{
    "id": 0,
    "name": "string"
}],
"status": "available"
}

From the response, you can find that the prefix tibco- is added to the pet name.

Example of Response Transformation

The following sample code shows how to add a field vendor with the value TIBCO to the response of the GET/pet/{petId} operation of the Petstore sample.

var _ = require('lodash');

if (_.isObject(body) && !_.isArray(body)) {
  body.vendor = 'TIBCO';
}
done(body);

After pushing the configured stage and running the Microflow app, query <Microflow endpoint>/pet/{petId}, for example, https://integration.cloud.tibco.com:98/7sytdyky0xvm6db69fkwdqqqt20i61z/pet/1.

You can find that a vendor field with the value TIBCO is added in the response.