nodehandler-dot
About
This module installs the doT Compose flow-node to be used within Axway API Builder's flow editor.
The Template flow-node allows the evaluation of doT templates using values from the flow.
Format string
The Format string method evaluates the doT template given with the data supplied. This allows complex values to be constructed from values that exist in the flow's context.
Param | Type | Required | Description |
---|---|---|---|
data | object | y | The data to evaluate the template with. Use $ to access the entire context. |
template | string | y | The doT template being evaluated. |
Format object
The Format object method is similar to the Format string method. It evaluates the doT template given with the data supplied. However the resulting string value is then JSON parsed. This allows the creation of JavaScript values and objects from the evaluated template.
Param | Type | Required | Description |
---|---|---|---|
data | object | y | The data to evaluate the template with. Use $ to access the entire context. |
template | string | y | The doT template being evaluated. |
doT Templates
doT is a JavaScript templating engine. As well as template evaluation, it supports features such as conditionals and iteration.
In the template, it is used to refer to the data
.
Example
In the examples the Flow is going to be attached to an API that has three parameters, firstname, lastname and gender.
Basic interpolation {{= }}
The template can be used to quickly concatenate values.
Request | http://localhost:8080/api/example?firstname=Clark&lastname=Kent&gender=m |
data | $ |
template | {{=it.params.firstname}} {{=it.params.lastname}} |
Output | Clark Kent |
Conditionals {{? }}
The template evaluation supports conditional logic to tailor the output based on the input.
Request | http://localhost:8080/api/example?firstname=Clark&lastname=Kent&gender=m |
data | $ |
template | Hello {{? it.gender=="m"}}Mr {{?}}{{? it.gender=="f"}}Ms {{?}}{{= it.surname}} |
Output | Hello Mr Kent |
Request | http://localhost:8080/api/example?firstname=Lois&lastname=Lane&gender=f |
data | $ |
template | Hello {{? it.gender=="m"}}Mr {{?}}{{? it.gender=="f"}}Ms {{?}}{{= it.surname}} |
Output | Hello Ms Lane |
Array Iteration {{~ }}
The template engine can also iterate over arrays, creating content for each element in the array.
Request | http://localhost:8080/api/example?names=Tom,Dick,Harry |
data | $ |
template | {{~it.params.names :value:index}}{{=index}}={{=value}};{{~}} |
Output | 0=Tom;1=Dick;2=Harry; |
Getting started
- Go to platform.axway.com and create an account
- Install API Builder
- Follow the Getting Started Guide
Install
After creating your API Builder project (appc new -t arrow
), you can install this flow-node handler
using npm:
npm install --save nodehandler-dot
The "Compose" flow-node will then be available in the tools panel when creating or editing Flows.