Reference

Template Helpers

The helpers Mocko adds on top of the Bigodon language, available in every mock body. Language-level helpers (strings, math, arrays, comparisons, dates) are in the Bigodon reference.

Response helpers

These render as an empty string; they change the response without adding content to the body.

HelperSignatureDescription
setStatus{{setStatus 404}}Override the response status for this request. Accepts a number or numeric string.
setHeader{{setHeader 'name' 'value'}}Add or override a response header. Case-insensitive; merges with the mock's headers block.
proxy{{proxy}}Forward the request and use the upstream response as the entire response. Halts template execution. See variants below.
log{{log 'message'}}Print to the server console. warn and error work the same at their log levels; objects are JSON-stringified.

proxy variants

{{proxy}}                                    {{! default backend (-u / PROXY_BASE-URI) }}
{{proxy 'https://demo-api.mockoapp.net'}} {{! URL used as base; request path appended }}
{{proxy 'billing'}} {{! destination of the named host block }}

The argument is a base: GET /users/42 through {{proxy 'https://demo-api.mockoapp.net'}} requests https://demo-api.mockoapp.net/users/42. Method, headers, query string, and body are forwarded unchanged.

Flag helpers

Flags are key-value state shared by all mocks and persisted according to the storage mode. The guided introduction is on Flags.

HelperSignatureDescription
setFlag{{setFlag 'key' value [ttlMs]}}Store a value (any JSON-serializable type). Optional TTL in milliseconds. Renders nothing.
getFlag{{getFlag 'key'}}Read a value; renders empty for unset keys. Render stored objects with {{json (getFlag 'key')}}.
hasFlag{{#hasFlag 'key'}}...{{/hasFlag}}True when the key exists; made for block position.
delFlag{{delFlag 'key'}}Delete a key. Renders nothing.
Keys containing : display as nested folders in the UI. Build dynamic keys with {{= $key (append 'users:' request.params.id)}}.

The request context

PathContents
request.params.<name>Path parameters from {name} segments in the route. Always strings.
request.query.<name>Query string parameters. Always strings.
request.headers.<name>Request headers, keyed lowercase regardless of how they were sent.
request.body.<field>Parsed JSON or form body fields (unless the mock sets parse = false).
data.<block>.<key>Values from data blocks.
Inside context-changing blocks like forEach, request and data are out of scope. Extract values to variables first or reach back with $root; see Templating.