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 }}
{{proxy '@billing'}} {{! same, but errors when the host doesn't exist }}

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.

A bare string that matches no host slug is proxied as a literal URL. Prefix the slug with @ to opt out of that fallback: {{proxy '@billing'}} fails the request with a clear error in the server log when no host has that slug or the host has no destination.

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 callback helper

Schedules delivery of a callback block after the mock responds. The guided introduction is on Callbacks.

HelperSignatureDescription
callback{{callback 'slug' [payload] [delay=ms]}}Schedule the named callback. The optional positional argument is the payload, any JSON-serializable value, available as payloadin the callback's templates at delivery time. delay=overrides the block's delay. Renders nothing.
An unknown slug or a host without a destination fails the mock with a 500. Callback bodies render with payload and data only, and support every helper except setStatus, setHeader, proxy, and callback itself.

The request context

PathContents
request.params.<name>Path parameters from {name} segments in the route. Always strings.
request.query.<name>Query string parameters. Strings, except a repeated key (?tag=a&tag=b) yields an array. Interpolating an array directly renders [object Array]; loop with forEach, which also treats a single value as a one-item list.
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.