How to configure TYK to redirect to appropriate backend service based on some header?

I am planning to use TYK as api gateway where I will be publishing different APIs.
Any of these APIs based on different information in header (or some other way), we want it to redirect to different backend application.

Looking for your help and suggestion to evaluate if this capability is present in TYK and how to achieve it.
The backends list is not static but keeps adding based on new backend registered specific for that header (for any such API).

We are currently using APIGEE, where we use KVM to store this information and based on different APIs need, we call relevant backend system.

Thanks & Regards
Amit

Have you had a look at our Advance Url Rewrite middleware? There is a snippet there that uses header matches and a session meta data for you to start with.

Or you could use this sample snippet below that works with a httpbin.org upstream to change the URL if a Digits header key is present with the value true .

"extended_paths": {
            "url_rewrites": [
              {
                "path": "/header_matches/alphanumeric",
                "method": "POST",
                "match_pattern": "/header_matches/alphanumeric",
                "rewrite_to": "/anything/header_matches/digits_is_not_true_or_does_not_exist",
                "triggers": [
                  {
                    "on": "all",
                    "options": {
                      "header_matches": {
                        "Digits": {
                          "match_rx": "true",
                          "reverse": false
                        }
                      },
                      "query_val_matches": {},
                      "path_part_matches": {},
                      "session_meta_matches": {},
                      "request_context_matches": {},
                      "payload_matches": {
                        "match_rx": ""
                      }
                    },
                    "rewrite_to": "/anything/header_matches/digits_is_true"
                  }
                ]
              }
            ]
          }

Thanks for the reply!!

Can you guide me how to make it dynamic? I am not looking to publish proxy again as I will be having few backends to be served and I will not be able to update the API definition based on new backend getting added. As mentioned, in APIGEE world, I use KVM to find appropriate backend based on the header.
I am also looking for few APIs, to call another service which tells me the appropriate backend for given header. So request path will be:
user–>tyk–>serviceDiscovery–>backend.
I would also like to cache the result from serviceDiscovery to ensure that calls to serviceDiscovery for a header is minimal.

Thanks & Regards
Amit

I can only assist to the best of my abilities. Your end result could vary from very simple to very complex. My best advice would be for you to write a custom plugin. Depending on your use case, this may be overkill but at least it gives you control on how you handle the request.

We some documentation regarding Service Discovery and Caching for your perusal.