Mock Alpha

Response Templates

Echo request data back in response bodies using {{request.X}} placeholders

Response Templates

Response templates let you build dynamic responses that reflect data from the incoming request. Any {{request.X}} placeholder in a scenario's response body is replaced at serve time with the actual value from the request.

Placeholder syntax

{{request.<source>.<key>}}
SourceExampleResolves from
query{{request.query.type}}URL query parameter ?type=...
body{{request.body.user.id}}JSON request body field (dot notation)
header{{request.header.x-tenant}}HTTP request header
path{{request.path.id}}Path parameter (e.g., /users/{id}id)

Usage

Write placeholders directly in the JSON response body editor. They work in string values at any nesting depth.

Query parameter

Scenario response body:

{
  "filter": "{{request.query.type}}",
  "results": []
}

Request: GET /api/products?type=premium

Response:

{
  "filter": "premium",
  "results": []
}

Request body field

Scenario response body:

{
  "userId": "{{request.body.id}}",
  "message": "Hello, {{request.body.user.name}}"
}

Request body:

{ "id": "abc123", "user": { "name": "Alex" } }

Response:

{
  "userId": "abc123",
  "message": "Hello, Alex"
}

Path parameter

For an endpoint with path pattern /devices/{id}:

Scenario response body:

{
  "deviceId": "{{request.path.id}}",
  "status": "online"
}

Request: GET /api/mock/devices/sensor-42

Response:

{
  "deviceId": "sensor-42",
  "status": "online"
}

Header value

Scenario response body:

{
  "tenant": "{{request.header.x-tenant}}",
  "data": []
}

Request with header X-Tenant: acme:

Response:

{
  "tenant": "acme",
  "data": []
}

MQTT payloads

The same {{request.X}} placeholders also work in MQTT topic payloads. When a topic is auto-published after an HTTP endpoint is hit, the same request context is available:

{
  "deviceId": "{{request.path.id}}",
  "timestamp": "{{request.body.ts}}",
  "event": "data-updated"
}

See MQTT Mock Server for how to configure auto-publish topics.

Edge cases

SituationBehaviour
Key not found in requestReplaced with empty string ""
Body is not valid JSONAll {{request.body.*}} placeholders replaced with ""
Malformed placeholder (e.g., {{request}})Left unchanged in the response
Placeholder inside a nested object or arrayResolved correctly — the replacement is recursive

On this page