重用APIM策略表达式 [英] Reusing APIM policy expressions

查看:84
本文介绍了重用APIM策略表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些复杂的策略表达式,我想在不同的操作之间重复使用.有没有一种方法可以在Azure APIM中实现这一目标?

I have some complex policy expressions which i want to reuse across different Operations. Is there a way to achieve this in Azure APIM?

策略表达式可以在不同的范围内使用,例如全局,产品,API或操作范围.非常清楚,让我们说我有一个效用函数,它被编写为策略表达式.我想在不同的API和不同的操作中重用它.目前,我需要在所有要使用它的地方复制复杂的表达式.我想知道是否有可能重用代码.

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.

推荐答案

如果您希望一次在APIM实例中定义一个策略,并且该策略存在于该实例的所有API中,则您想定义一个基本政策.当您查看新创建的API的策略页时,它将看起来像这样:

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 />是指为All APIs定义的任何入站/后端/出站/错误策略.要获取该政策文件,请参见下图

<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

您在所有API中定义的策略均通过<base />标记导入.

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

使用命名值可能还有助于代码重用.

Using Named Values may also facilitate code reuse.

这篇关于重用APIM策略表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆