Transforming DX Engine Component Responses

This blog post describes five different techniques that you can use to transform the response of a Conscia DX Engine Orchestration Component. If you have any information or questions about transforming Component responses, please comment on this blog post.

In the Conscia DX Engine, an Orchestration Component is responsible for one discrete function in an orchestration flow. For example, an individual Orchestration Component could call a single Webservice API in a customer or third-party back-end system. By default, the response of that Component, which is available to other Components in the orchestration flow, is the response of that Webservice API. The response of most components a JSON payload.

In many cases, you need to transform the response from a Webservice API to a different JSON format, or simply reduce the size of the payload by removing irrelevant entries, before using that data in subsequent Components in an orchestration flow.  

You can use at least five different techniques to alter the response of a Component. To some extent, the choice of which to use is a matter of developer preference.

Property Mapper

You can create a Property Mapper Orchestration Component and define a target schema of named keys with an expression to indicate the location of the source value in the JSON response from the Component that calls the Webservice API.

Use Property Mapper where:

  • Not all uses of the Component should apply the same response transformation.
  • You need to reduce the JSON payload and rename some keys in a flat list.
  • You only need to map a few simple properties.

Object Mapper

You can create an Object Mapper Orchestration Component that provides a drag-and-drop interface for defining the target JSON structure and the source values for each property.

Use Object Mapper where not all uses of the Component should apply the same response transformation.

Response Transform

You can enter a JavaScript expression for the Response Transform property in the Main area of the definition of the Component. After the DX Engine invokes the Component, it applies the Response Transform to its result.

An advantage of response transformation is that the retrieval and reformatting logic are self-contained in a single Component.

All uses of the Component apply the same Response Transformation, so it is not always appropriate where the same Component collect different data or formats for different subsequent Components.

Along with Data Transformation Scripts, Response Transformation is appropriate when the problem seems better-suited to code rather than configuration.

Response Transformation occurs after invoking Sub Components.

Handlebars Template in Response Transform

You can use Handlebars templates in Response Transformation of the Component that calls the Webservice API.

The following example adds keys named MyID and MyName to the Component’s response, including MyID only if the Webservice API’s response contains id. This is just an example; Handlebars provides looping and other constructs (I haven’t considered use cases).

_.assign(response, JSON.parse(processHandlebars(
'{ {{#if id}}"MyID": "{{id}}",{{/if}} "MyName": "{{name}}"}',
response)))

That example uses the assign() function in the Lodash library.

If you want the Component’s response to contain only the MyID and MyName keys, you can set Response Transform without using the assign() function:

JSON.parse(processHandlebars(
'{ {{#if id}}"MyID": "{{id}}",{{/if}} "MyName": "{{name}}"}',
response))

Data Transformation Script

You can create a Data Transformation Script (DTS) Orchestration Component that passes data such as the response from a Component that calls a Webservice API to arbitrary JavaScript, the result of which becomes the response of the DTS Component.

Use Data Transformation Scripts where one or more of the following is true:

  • The problem seems more appropriate for code than configuration.
  • Not all uses of the Component should apply the same response transformation.
  • You cannot achieve your objective with Response Transformation.

2 thoughts on “Transforming DX Engine Component Responses

Leave a comment