Skip to content

response-transformer

The response-transformer plugin modifies responses before they reach the client.

  • Phase: Response
  • Purpose: Transform response headers and body
  • Behavior: Applies transformations before returning to client
{
"pluginName": "response-transformer",
"config": {
"add": {
"headers": ["X-Gateway-Version: 1.0"]
},
"set": {
"headers": ["X-Response-Time: ${duration_ms}"]
},
"remove": {
"headers": ["X-Internal-*"]
},
"rename": {
"headers": ["X-Backend: X-Source"]
}
}
}

Use variables in transformations:

VariableDescription
${request_id}Unique request ID
${duration_ms}Request duration (ms)
${status}Response status code
${consumer.id}Consumer ID (if auth)
${route.id}Matched route ID
${service.id}Matched service ID

Example:

{
"set": {
"headers": ["X-Response-Time: ${duration_ms}ms"]
}
}

Transform JSON response body fields:

{
"add": {
"body": ["gateway_processed: true"]
},
"remove": {
"body": ["internal_metadata", "debug_info"]
},
"rename": {
"body": ["backend_id: gateway_id"]
}
}

Use both plugins for full request/response transformation:

Terminal window
# Request transformation
curl -X POST http://localhost:8080/api/plugins \
-d '{"serviceId":"service_abc","pluginName":"request-transformer","config":{"add":{"headers":["X-Source: gateway"]}}}'
# Response transformation
curl -X POST http://localhost:8080/api/plugins \
-d '{"serviceId":"service_abc","pluginName":"response-transformer","config":{"add":{"headers":["X-Via: gateway"]}}}'

Use * for pattern matching:

{
"remove": {
"headers": ["X-Backend-*", "X-Debug-*"]
}
}

Removes all headers matching the pattern.

Use regex for complex replacements:

{
"replace": {
"headers": ["Server: Apache: MiniGateway"]
}
}