0

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.

  • In a given API, policy expressions impact all operations by default. Could you add more detail to your question to make it more clear? – BobbyA Apr 04 '19 at 18:23
  • Hi Bobby, Thanks for the comment. 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. – srinivasa mahendrakar Apr 04 '19 at 22:42

1 Answers1

3

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

enter image description here

The policies you define there are imported by the <base /> tag in all your APIs.

Using Named Values may also facilitate code reuse.

BobbyA
  • 2,090
  • 23
  • 41