Reputation: 21
Can API Management rewrite a backend URL to be the value of a request header? For example, if I have a request originating with header X-ProxyTarget: https://api.ipify.org/
, and I send it to https://my-api.azure-api.net/proxy
then can a policy (or combination of policies) on inbound (or backend) forward the request to https://api.ipify.org
?
Upvotes: 2
Views: 508
Reputation: 533
You can use the set-backend-service policy in the inbound section. This policy updates the backend URL as provided and read the input header value to set the url. Sample Code:
<set-backend-service base-url="@(context.Request.Headers.GetValueOrDefault("X-ProxyTarget","http://my-api.net"))" />
References : https://learn.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#SetBackendService
Upvotes: 2