Response transformation


From above what is the way to set a transformed body to the kong.response ? Say if I have LUA json table that I owuld like to set on the response using a custom plugin.


kong.response.exit will allow you to return any kind of response back to the client. (e.g. kong.response.exit(200, {"foo" : "bar"}))

For many use cases, the response-transformer at is enough. Just making sure you know about of it.

Hi @Raimon_Grau thanks for that.

My use case is to transform a complex Json from the backend service response into a slightly different format before being sent downstream.

The Json has nested structures so the basic response-transformer wasn’t enough for me or I didnt know how to use it for this.

I have scenarios like to drop a top level json name but keep contents inside also.


@saravana Please have a look at the code of the response-transformer plugin:

This should you give an idea of how to use the cjson module and Lua to drop the JSON attribute.