# Body Transformer Configuration

The `body-transformer` plugin uses templates to transform request and response bodies between formats required by clients and upstream services.<!-- --> <!-- -->Configuration covers plugin parameters.

## Parameters[​](#parameters "Direct link to Parameters")

See plugin [common configurations](https://docs.api7.ai/apisix/reference/plugin-common-configurations.md) for configuration options available to all plugins.

* request

  object

  ***

  Request body transformation configuration.

  * input\_format

    string

    valid value:

    `xml`, `json`, `encoded`, `args`, `plain`, or `multipart`

    ***

    Request body original media type. If unspecified, the value would be determined by the `Content-Type` header to apply the corresponding decoder.

    The `xml` option corresponds to `text/xml` media type. The `json` option corresponds to `application/json` media type. The `encoded` option corresponds to `application/x-www-form-urlencoded` media type. The `args` option corresponds to GET requests. The `plain` option corresponds to `text/plain` media type. The `multipart` option corresponds to `multipart/form-data` media type.

    If the media type is not one of the supported types, the value would be left unset and the transformation template will be directly applied.

  * template

    string

    required

    ***

    Request body transformation template. The template uses [lua-resty-template](https://github.com/bungle/lua-resty-template) syntax. See the [template syntax](https://github.com/bungle/lua-resty-template#template-syntax) for more details.

    You can also use auxiliary functions `_escape_json()` and `_escape_xml()` to escape special characters such as double quotes, `_body` to access request body, and `_ctx` to access context variables. See [examples](https://docs.api7.ai/hub/body-transformer.md#examples) to learn more.

    The template names `_ctx`, `_body`, `_escape_json`, `_escape_xml`, and `_multipart` are reserved; `_escape_json()` and `_escape_xml()` are called as functions. Decoded request fields with these names are ignored so that they cannot replace the helpers.

  * template\_is\_base64

    boolean

    ***

    Set to true if the template is base64 encoded.

* response

  object

  ***

  Response body transformation configuration.

  * input\_format

    string

    valid value:

    `xml`, `json`, `encoded`, `args`, `plain`, or `multipart`

    ***

    Response body original media type. If unspecified, the value would be determined by the `Content-Type` header to apply the corresponding decoder.

    The `xml` option corresponds to `text/xml` media type. The `json` option corresponds to `application/json` media type. The `encoded` option corresponds to `application/x-www-form-urlencoded` media type. The `args` option is primarily used for request query arguments and is typically not applicable to response bodies. The `plain` option corresponds to `text/plain` media type. The `multipart` option corresponds to `multipart/form-data` media type.

    If the media type is none of the supported types, the value would be left unset and the transformation template will be directly applied.

  * template

    string

    required

    ***

    Response body transformation template.

    The template names `_ctx`, `_body`, `_escape_json`, `_escape_xml`, and `_multipart` are reserved; `_escape_json()` and `_escape_xml()` are called as functions. Decoded response fields with these names are ignored so that they cannot replace the helpers.

  * template\_is\_base64

    boolean

    ***

    Set to true if the template is base64 encoded.

* max\_req\_body\_size

  integer

  default: `67108864`

  valid value:

  greater than or equal to 1

  ***

  Maximum request body size in bytes read for transformation. A larger body is rejected with status `413`. Introduced in API7 Enterprise 3.9.17 and 3.10.4, and APISIX 3.18.0.

* max\_resp\_body\_size

  integer

  default: `67108864`

  valid value:

  greater than or equal to 1

  ***

  Maximum response body size in bytes buffered for transformation. A larger response is truncated to this size before transformation. The chunk that crosses the threshold is buffered before the limit is enforced, so transient memory use can exceed the configured size. Introduced in API7 Enterprise 3.9.17 and 3.10.4, and APISIX 3.18.0.
