Last update: Oct 25, 2022
The content replacer plugin allows you to modify the response of your services by doing literal replacements or more sophisticated replacements with regular expressions.
The plugin works both in the endpoint
and the backend
sections. Depending on what stage of the pipe you want to modify, the content is replaced before it gets to the user (endpoint) or before the merging operation (backend).
The content to replace must be a string and located inside an object or a children object. You cannot replace objects, arrays, or any other type, or access elements inside arrays.
{
"extra_config": {
"plugin/req-resp-modifier": {
"name": [
"content-replacer"
],
"content-replacer": {
"data.credit_card": {
"@comment": "Ridiculous card masking. Take 4 digits and remove the rest. Credit card is inside a data object.",
"find": "(^\\d{4})(.*)",
"replace": "${1}-XXXX",
"regexp": true
},
"message": {
"@comment": "Replace '6 items left' with '6' on the message field",
"find": " items left",
"replace": ""
}
}
}
}
}
| The find expression or literal you want to use. |
| When you are passing regular expressions instead of literal values, set it to true. Defaults to false |
| The literal string or expression you want to use as a replacement. |
* indicates a required field. Parameters in alphabetical order.
The configuration of the plugin uses as keys the objects of the response. The dot .
notation is reserved to access nested elements and you cannot use fields containing dots as part of the key name with this plugin. In the example above, the data.credit_card
represents a nested object, like:
{
"data": {
"credit_card": "1234-56789-1234-5678"
}
}
The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.
We use cookies to understand how you use our site and to improve your overall experience. By continuing to use our site, you accept our Privacy Policy. More information