← Docs

Templates

Middleman templates transform the JSON body of an incoming proxy request before it's forwarded to your target.

They run only when both:

If either is missing, the original body is forwarded unchanged.

Invalid templates are rejected at save time. A runtime failure (e.g. drilling into a field that isn't an object) falls back to forwarding the original body — the failure is recorded on the matching row in the dashboard's History tab.

Reference incoming fields

An identifier (a bareword like email) looks up the field with that name in the incoming body.

Input body

{
  "email": "ada@example.com",
  "amount": 9900
}

Template

{
  "to": email,
  "cents": amount
}

Output

{
  "to": "ada@example.com",
  "cents": 9900
}

Identifiers also work as field names — the key itself comes from the incoming body:

{
  event_type: payload
}

Nested fields

Dot notation drills into nested objects:

{
  "name": user.profile.display_name,
  "country": user.address.country
}

Conditional values

Ternary form — if (cond) X : Y:

{
  "tier": if (is_premium) "paid" : "free"
}

Without an else branch, the field is omitted entirely when the condition is false:

{
  "discount_code": if (has_discount) discount_code
}

Conditional field groups

Use cond ? { ... } to merge a block of fields only when a condition holds — handy for grouping several related fields under one gate:

{
  "id": user_id,
  is_premium ? {
    "plan": plan_name,
    "renews_at": renewal_date
  }
}

Negation

Prefix any condition with ! to invert it:

{
  "anonymous": if (!is_logged_in) true : false
}
← Docs