Reputation: 228
I have some complex policy expressions which i want to reuse across different Operations. Is there a way to achieve this in Azure APIM?
The policy expressions can be used at different scopes such as Global, Product, API or operational scopes. To be very clear,let us say i have a utility function which is written as a policy expression. I want to reuse it in different APIs , as well as at different Operations. At the moment i need to copy the complex expression in all places where i want to use it. I want to know if there is any possibility to reuse the code.
Upvotes: 0
Views: 1074
Reputation: 2260
If you're looking to define a policy once in an instance of APIM, and have it be present across all of that instance's APIs, you want to define a base policy. When you look at a policy page of a newly created API, it will look like this:
<policies>
<inbound>
<base />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
<base />
refers to whatever inbound/backend/outbound/on-error policies are defined for All APIs
. To get to that policy document, see the image below
The policies you define there are imported by the <base />
tag in all your APIs.
Using Named Values may also facilitate code reuse.
Upvotes: 3