I am currently in the middle of publishing an internal API and would really like to use Tyk Cloud as an authentication and mapping layer. The internal API is unfortunately not changeable and the public API shall only return a subset of the fields provided by the internal API - some fields also under a new label. So my approach is to use body transforms on the response content (JSON) provided by the internal API in order to relabel and remove certain fields.
However, I am struggling with several issues:
When setting up a body transform and a URL Rewrite rule the body transformation is not executed. I am still getting the original API response.
Whenever I run a body transform on any request, as shown in your docs, all REST clients (Postman, various other REST clients) will stop processing the response. They simply output errors like “ERROR: Failed to contact server” (insomnia), Could not get any response (postman), etc. It’s like the connection just broke off for these clients. cURL, however, works just fine and gets the response without complaint. I compared the output in curl before and after the change,a long with status headers and they are identical. When I remove the body transform the response is recognized by all clients again.
How does body transform handle non 200 responses with errors inside? The body transform template would not fit the content any more.
I am not yet very versed in go template. Is it possible to walk through nested responses change the output of each item accordingly?
Response transforms need to be targetted on the rewritten URL, not on the inbound one.
Not sure what’s wrong here, we test with Postman all the time, body trnsforms only impact the body of the request and change the content size param, nothing more. Maybe you are responding with the wrong headers. Or the template is crashing, also likely.
The body transform will just try to transform the returned body, regardless of status code
In your example, you may have a problem, since the inbound JSON object has no anchorable fields, so you can’t identify the list as a golang template variable (you might be able to use . (the main context dot), but you’d need to experiment.
That puzzled me a bit, but ok. So I created a second endpoint pointing to the internal API endpoint, setup the body transformation there and put the endpoint on the blacklist, so it won’t be accessible. Works! Awesome! Alas, I am running into the second issue again:
I find this really weird too, but perhaps I am doing something wrong?! I have attached a short screencast to illustrate (I even tried with something simpler, like removing all but on field - doing the transform on another endpoint. But the result is always the same)
@gawonmi Did you ever get a fix for your second issue - the one where Postman was returning “Could not get any response”? I’m experiencing the same thing. This is my first attempt at transforming a response body.