Useful helper functions

Concatenate two strings

{{ concat <string1> <string2> }}

Search and replace text in a string

{{ replace <string-to-search> <string-to-replace> <replacement-string> }}

Create an array from a delimited string

This can be particularly useful when dealing with the results of a JsonPath query that returns an array, as these are space delimited strings of values.

{{ split <delimited-string> '<delimiter>' }}

Change the HTTP response code

If you are following a pattern where you want a single request/response pair to return different HTTP response codes based on the outcome of logic, then you can do that using the following function:

{{ setStatusCode <any-valid-http-response-code> }}

12. Avoiding HTML encoding in function return values

By default the handlebars engine will HTML escape every value it returns into the template.

What this means is that if the value returned from any function contains one of the HTML special characters, then they will be replaced with their escaped equivalent.

Character
Description
Escaped Equivalent

&

Ampersand

&amp;

<

Less than

&lt;

>

Greater than

&gt;

"

Double quote

&quot;

'

Single quote

&apos; or &#39;

©

Copyright symbol

&copy;

®

Registered symbol

&reg;

Trademark symbol

&trade;

In order to avoid this behavior, you need to enclose the function in triple handlebar syntax.

for example:

{{faker 'Question'}} 

might return

You probably haven&apos;t heard of them?

where as, if used with triple handlebars:

{{{faker 'Question'}}} 

might return

You probably haven't heard of them?

Last updated