Skip to main content

Module body_transformer

Module body_transformer 

Source
Expand description

The body-transformer node — rewrites the request and/or response body from a template.

§Deviation from APISIX (read this first)

APISIX’s body-transformer renders full lua-resty-template templates (arbitrary Lua expressions, loops, helpers) over bodies decoded from xml, json, encoded, args, plain, or multipart input. featherbit implements a deliberate subset:

  • input_format supports json only (other formats are rejected at config load; omitting it defaults to json).

  • Templates are plain strings with two placeholder forms:

    • {{body.x.y}} — a dotted path resolved from the parsed JSON body (numeric segments index arrays; {{body}} is the whole document). Strings are inserted raw (unquoted), numbers/bools verbatim, missing values and null as the empty string, and objects/arrays as compact JSON.
    • {{$var}} — a context variable via crate::vars::resolve ($uri, $http_x_id, $arg_page, …).

    Text outside {{ }} additionally passes through crate::vars::interpolate, so bare $var references work there too.

  • template_is_base64 is not supported (templates are stored literally in YAML) and is rejected at config load.

Structs§

BodyTransformerPlugin
Rewrites context.request.body and/or context.response.body by rendering a template against the parsed JSON body and context variables.

Functions§

json_path 🔒
Resolves a dotted path (x.y.0) inside a JSON value; an empty path returns the value itself.
json_to_template_string 🔒
Stringifies a resolved JSON value for template insertion: strings raw, scalars verbatim, null empty, containers as compact JSON.
parse_body 🔒
Parses a body as JSON; empty bodies become null so templates still render (with empty {{body...}} placeholders).
parse_transform 🔒
Validates one request/response transform object and returns its template string.
render 🔒
Renders a template: {{body.path}} from the parsed body, {{$var}} via crate::vars::resolve, and $var interpolation on the literal text between placeholders. Unknown placeholders resolve to the empty string; values substituted from the body are not re-interpolated.