Response Templating - String Encodings

WireMock Cloud provides several helpers for encoding and decoding values to/from various formats.


The base64 helper encodes and decodes Base64:

{{{base64 request.headers.X-Plain-Header}}}
{{{base64 request.headers.X-Plain-Header padding=false}}}
{{{base64 request.headers.X-Encoded-Header decode=true}}}

Content to encode     

{{{#base64 decode=true}}}


The urlEncode helper encode and decode values according to the HTTP URL encoding standard:

{{{urlEncode request.headers.X-Plain-Header}}}
{{{urlEncode request.headers.X-Encoded-Header decode=true}}}

Content to encode     

{{{#urlEncode decode=true}}}


The formData helper parses its input as an HTTP form, returning an object containing the individual fields as attributes. The helper takes the input string and variable name as its required parameters, with an optional urlDecode parameter indicating that values should be URL decoded.

The folowing example will parse the request body as a form, then output a single field formField3:

{{formData request.body 'form' urlDecode=true}}{{{form.formField3}}

If the form submitted has multiple values for a given field, these can be accessed by index:

{{formData request.body 'form' urlDecode=true}}}{{{form.multiValueField.1}}, {{{form.multiValueField.2}}
{{formData request.body 'form' urlDecode=true}}}{{{form.multiValueField.first}}, {{{form.multiValueField.last}}