response-transformer
The response-transformer plugin modifies responses before they reach the client.
Overview
Section titled “Overview”- Phase: Response
- Purpose: Transform response headers and body
- Behavior: Applies transformations before returning to client
Configuration
Section titled “Configuration”{ "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"] } }}Transformation Types
Section titled “Transformation Types”Usage Example
Section titled “Usage Example”Template Variables
Section titled “Template Variables”Use variables in transformations:
| Variable | Description |
|---|---|
${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"] }}Body Transformation
Section titled “Body Transformation”Transform JSON response body fields:
{ "add": { "body": ["gateway_processed: true"] }, "remove": { "body": ["internal_metadata", "debug_info"] }, "rename": { "body": ["backend_id: gateway_id"] }}Combining with request-transformer
Section titled “Combining with request-transformer”Use both plugins for full request/response transformation:
# Request transformationcurl -X POST http://localhost:8080/api/plugins \ -d '{"serviceId":"service_abc","pluginName":"request-transformer","config":{"add":{"headers":["X-Source: gateway"]}}}'
# Response transformationcurl -X POST http://localhost:8080/api/plugins \ -d '{"serviceId":"service_abc","pluginName":"response-transformer","config":{"add":{"headers":["X-Via: gateway"]}}}'Wildcard Patterns
Section titled “Wildcard Patterns”Use * for pattern matching:
{ "remove": { "headers": ["X-Backend-*", "X-Debug-*"] }}Removes all headers matching the pattern.
Regex Replacement
Section titled “Regex Replacement”Use regex for complex replacements:
{ "replace": { "headers": ["Server: Apache: MiniGateway"] }}Best Practices
Section titled “Best Practices”See Also
Section titled “See Also”- request-transformer - Transform requests
- cors - CORS headers
- logger - Response logging