Reusing APIM policy expressions

偶尔善良 提交于 2019-12-20 05:56:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/55522586/reusing-apim-policy-expressions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!