npm

Need private packages and team management tools?Check out npm Orgs. »

@axway/api-builder-plugin-fn-dot

1.0.14 • Public • Published

api-builder-plugin-fn-dot

About

This plugin 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

  1. Follow the Getting Started Guide

Install

After creating your API Builder service (api-builder init), you can install this plugin using npm:

npm install --save @axway/api-builder-plugin-fn-dot

The "Compose" flow-node will then be available in the tools panel when creating or editing Flows.

Changes

1.0.14

  • #5050: Updating license text.

1.0.8

  • #4757: Changed SCM repository and associated internal cleanup.

License

This code is proprietary, closed source software licensed to you by Axway. All Rights Reserved. You may not modify Axway’s code without express written permission of Axway. You are licensed to use and distribute your services developed with the use of this software and dependencies, including distributing reasonable and appropriate portions of the Axway code and dependencies. Except as set forth above, this code MUST not be copied or otherwise redistributed without express written permission of Axway. This module is licensed as part of the Axway Platform and governed under the terms of the Axway license agreement (General Conditions) located here: https://support.axway.com/en/auth/general-conditions; EXCEPT THAT IF YOU RECEIVED A FREE SUBSCRIPTION, LICENSE, OR SUPPORT SUBSCRIPTION FOR THIS CODE, NOTWITHSTANDING THE LANGUAGE OF THE GENERAL CONDITIONS, AXWAY HEREBY DISCLAIMS ALL SUPPORT AND MAINTENANCE OBLIGATIONS, AS WELL AS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO IMPLIED INFRINGEMENT WARRANTIES, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, AND YOU ACCEPT THE PRODUCT AS-IS AND WITH ALL FAULTS, SOLELY AT YOUR OWN RISK. Your right to use this software is strictly limited to the term (if any) of the license or subscription originally granted to you.

install

npm i @axway/api-builder-plugin-fn-dot

Downloadsweekly downloads

32

version

1.0.14

license

SEE LICENCE IN LICENSE

repository

Gitgit

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability