I would like to create a policy in Azure API Management that forwards all calls that start with the path "proxy/search" to another url. However, i don't want to have to import/create endpoints in APIM for every possibility since this makes it a maintenance nightmare. For example..
to the corresponding...
I've built the policy below but it looks like APIM wants exact routes to map from it to the backend. I don't want to do this because this proxy may be forwarding to many, many routes apis etc...
<policies>
<inbound>
<base />
<set-variable name="baseUrlSearch" value="https://mysearchapi.com/" />
<set-variable name="matchSearch" value="proxy/search" />
<set-variable name="isRoutingComplete" value="false" />
<set-variable name="apiVersionDefaultSearch" value="1.0" />
<choose>
<when condition="@{return context.Request.Url.Path.Contains(context.Variables.GetValueOrDefault<string>("matchSearch"));}">
<set-backend-service base-url="@(context.Variables.GetValueOrDefault<string>("baseUrlSearch"))" />
<rewrite-uri template="@(context.Request.Url.Path.Replace(context.Variables.GetValueOrDefault<string>("matchSearch"), ""))" />
<set-header name="Api-Version" exists-action="skip">
<value>@(context.Variables.GetValueOrDefault<string>("apiVersionDefaultSearch"))</value>
</set-header>
<set-variable name="isRoutingComplete" value="true" />
</when>
<when condition="@(!context.Variables.GetValueOrDefault<bool>("isRoutingComplete"))">
<return-response>
<set-status code="400" reason="Bad Request Through Proxy" />
</return-response>
</when>
</choose>
</inbound>
<outbound>
<base />
</outbound>
</policies>
Azure Application Gateway is a platform as a service (PaaS) that acts as a Layer-7 load balancer. It acts as a reverse-proxy service and provides among its offerings Azure Web Application Firewall (WAF).
While API Gateways and API management can be used interchangeably, strictly speaking an API gateway refers to the individual proxy server, while API management refers to the overall solution of managing APIs in production which includes a set of API gateways acting in a cluster, an administrative UI, and may even ...
You are making your life much harder than it needs to be. Simply create an operation that uses /proxy/*
as the template and it will match to all the URLs you identified.
Then just create a policy for that operation that does set-backend-service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With