Using the response transformer advanced plugin for kong, it looks like it is possible to replace urls in the body of an api.
The use case: you have an api that you have set to return hypermedia links as absolute urls to other resources.
The problem is that you have given the other party access to your api only by way of kong – an api gateway.
That means that the url’s in the response body point to an api they do not have direct access to.
For example your api responds with a body:
Your api gateway is
https://api.fixes.co.za, so you want to update the response to convert to:
Is it possible?
My search term:
Lua function to replace occurances of base url in json body.
With the standard request transformer it does not look possible.
The closest would be
config.replace.json which does
List of property:value pairs. If and only if the parameter is already present, replace its old value with the new one. Ignored if the parameter is not already present.
I want to string replace anywhere
https://virtualisation.fixes.co.za/ is found and replace it with
In any value or nested value.
It looks like the only way to do it would be with a custom lua function in a
config.transform.functions of the pay for response transformer advanced
So you have to pay for kong enterprise, learn lua and then apply the function. To achieve this.