HTTP response transform: Does Tyk have a built-in feature to transform HTTP status and status codes?

I’m curious to know if Tyk includes a built-in transform for changing the HTTP status and status code. Additionally, I’m wondering if it’s possible to modify the HTTP status code based on the content of the response body. for example, if the value of the body response’s property “error” is true, then change the status code to 400.

Do you know if this can be achieved solely using Tyk’s built-in features, or would a custom plugin be necessary? As of now, my current solution is using custom Golang plugin.

Hi toto35711;
Using custom plugin is an option to modify the HTTP payload (status and code) or you can use Virtual endpoints to modify them. (Virtual Endpoint Demonstration)

using virtual endpoint, does it mean that I should make an API call to the upstream manually using the JavaScript? How is the execution order if I add another endpoint designer functionality such as response body transform?

Please see our middleware execution order documentation to understand the flow of the request chain. However, to summarise, using a virtual endpoint would skip the post-middleware and proxy lifecycle. This means a response middle would not be triggered.

Yes, we have a couple of Javascript APIs at your disposal but please be aware that JS plugins and virtual endpoints are run in a Sandboxed JSVM powered by [Otto engine] (GitHub - robertkrimen/otto: A JavaScript interpreter in Go (golang)) that is compiled in the Gateway binary. You are limited to the bare bones of a scripting language and there is no support for CoreJS, ES6, and above.

You can find examples to get you started with virtual endpoints here