Skip to content

Template helpers

This is the reference list. For the concept and a worked example, start with templating.

Activation

ScopeHow
One stub"transformers": ["response-template"] on the response
Whole hostStart the server with --global-response-templating
WebhooksAutomatic — webhook fields are templated with no transformer needed

The request model

These are data paths, not helpers — read them directly.

PathValue
request.methodHTTP method
request.urlFull URL including query string
request.pathPath; request.path.[n] for a segment; request.path.<name> when the stub used urlPathTemplate
request.pathSegments.[n]Path segment by index
request.query.<name>Query parameter
request.headers.<Name>Request header
request.cookies.<name>Cookie
request.bodyRaw body
request.bodyAsBase64Body, base64-encoded
request.host
request.port
request.scheme
request.baseUrl
request.parts.<name>Multipart part; has .body, .name, .headers.<H>

Named path variables such as request.path.id only resolve if the stub matched through urlPathTemplate. See request matching.

The root object differs by context:

ContextRoot
Response templatingrequest
WebhookoriginalRequest
WebSocket message mappingmessage.body

Data helpers

HelperPurpose
jsonPathExtract a value from JSON with a JSONPath expression
xPathExtract a value from XML with an XPath expression
regexExtractExtract a capture from a string with a regex
formDataRead a form-encoded body into named fields
parseJsonParse a JSON string; available in inline and block form
assignBind a value to a name; block form

Date helpers

HelperPurpose
parseDateParse a string into an instant
dateFormat an instant
nowCurrent time; accepts offset= and a format pattern
truncateDateTruncate an instant to a unit

Random helpers

HelperPurpose
randomValueRandom value of a given type=, e.g. UUID
pickRandomPick one element at random
randomIntRandom integer
randomDecimalRandom decimal

JSON helpers

HelperPurpose
jsonArrayAddAppend to a JSON array
jsonMergeMerge two JSON objects
jsonRemoveRemove a node from JSON
toJsonSerialize a value to JSON

Format, math, string and array helpers

HelperPurpose
mathArithmetic; supports + - * / only
numberFormatFormat a number
sizeLength of a string or collection
joinJoin a collection with a separator
substringSubstring by index
replaceReplace occurrences in a string
upperUppercase
lowerLowercase
capitalizeCapitalize
trimStrip surrounding whitespace
base64Base64-encode
urlEncodeURL-encode
formatJsonPretty-print JSON
formatXmlPretty-print XML
isOddOdd-number test
isEvenEven-number test
rangeProduce a numeric range
arrayBuild an array from arguments
lookupRead a value out of a collection by key or index
arrayAddAppend to an array

System helpers

HelperPurpose
systemValueRead a system/environment value
hostnameHost name of the running server

Fake data

One helper, random, taking a Datafaker-style expression string:

{{random 'Name.fullName'}}
ClassMethods
NamefirstName, lastName, fullName, name, username, prefix
InternetemailAddress, url, uuid, domainName, ipV4Address, macAddress
Addresscity, country, countryCode, zipCode, state, stateAbbr, streetAddress, streetName, buildingNumber, secondaryAddress, fullAddress, latitude, longitude
Numberdigit
Companyname
CommerceproductName
Loremword, sentence
PhoneNumberphoneNumber, cellPhone

An unrecognised expression renders the literal text [ERROR: Unable to evaluate the expression <expr>] into the response rather than failing the request.

Argument-taking faker expressions such as Number.numberBetween are not supported. Locale selection is not supported either.

JWT helpers

HelperPurpose
jwtProduce a signed JWT
jwksProduce a JWKS document

Handlebars built-ins

{{#if}}, {{#each}}, {{#unless}} and {{#with}} are available as normal.

Helpers that do not exist

Several helper names appear in third-party references and even in the dashboard’s helper popup, but are not registered in the engine. The engine is the authority.

NameUse instead
addmath
subtractmath
multiplymath
dividemath
round
abs
soapXPathxPath