Reputation: 8009
Is it possible to, within policy, get the specified url part below:
<policies>
<inbound>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
<find-and-replace from="https://thirdparty/certs"
to="@(specified url part)" />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Please note that the whole url might include versioning and prefix.
Upvotes: 5
Views: 15377
Reputation: 7810
The whole URI (let's assume https://contoso.com/myapi/.wellknown/openid-config) is comprised of:
context.Request.OriginalUrl.Scheme
context.Request.OriginalUrl.Host
context.Request.OriginalUrl.Port
context.Api.Path
So operation part of URL can be calculated by something close to: context.Request.OriginalUrl.Path.Trim('/').Substring(context.Api.Path.Trim('/').Length)
Upvotes: 12
Reputation: 1811
Example of a policy expression, that when used in the inbound path can be used to redirect an incoming request based on version information included as a query parameter in a published API.
<choose>
<when condition="@(context.Request.Url.Query.GetValueOrDefault("version") == "2014-03")">
<set-backend-service base-url="http://contoso.com/api/1.6/" />
</when>
<otherwise>
<set-backend-service base-url="http://contoso.com/api/2.0/"
</otherwise>
</choose>
Find more details at https://azure.microsoft.com/en-us/blog/policy-expressions-in-azure-api-management/
Upvotes: 0