Conditional request body transformation

Hi there,

I’m trying to figure out if Tyk could be a fit for my (not so particular) need.

Let’s say I have shops using the same app which exposes a /foo endpoint.

This endpoint exists in two versions (/v1/foo and /v2/foo) but not all shops expose both versions (v2 is only available in the latest version of the app).

I I were to use Tyk to handle requests to these endpoints for all shops, would there be a way to transform the request depending on the targeted shop’s capabilities?

For instance, a v2 request would need to be transformed into a v1 request if the shop can only handle /v1/foo, otherwise the request would just be forwarded to the shop without any transfomation.

Thanks.

Hi @Bok,

Thank you for your question, and welcome to the community! :partying_face:

Yes, this is possible with Tyk; the key is to have a way to identify or determine each shop’s capabilities.

For straightforward cases, e.g where the request contains such a header, X-Supports-V2, URL Rewrite Middleware (with advanced triggers), will be suitable.
For more advanced setups, you could implement a Custom Javascript or Python Request Plugin that will contain the lookup logic and can modify the target URL before it’s proxied upstream.

Please find resources in our docs:

Please let us know if this approach works for you, or if you run into any issues while implementing it.

Best regards,