我刚刚开始使用 Apigee。
我想创建一个 API 代理,它将根据“if”条件调用两个目标端点。
我已经创建了一个 API 并向其中添加了资源,但问题是在这种情况下我得到了两个 API。
如果type='abc'目标点应该是target1
如果 thetype='xyz' 目标点应该是 target2
谁能告诉我如何继续吗?
查看答案这个问题。此处列出了查找 RouteRules 的详细信息。这ProxyEndpoint 文档也会有帮助的。
您可以使用此代码完成您尝试的操作:
<RouteRule name="routeToTarget1">
<Condition>thetype == "abc"</Condition>
<TargetEndpoint>target1</TargetEndpoint>
</RouteRule>
<RouteRule name="routeToTarget2">
<Condition>thetype == "xyz"</Condition>
<TargetEndpoint>target2</TargetEndpoint>
</RouteRule>
这些 RouteRules 将按顺序进行评估。
请注意,您可能希望底部 RouteRule 没有条件,这意味着它将始终匹配。当类型不等于“abc”或“xyz”时会发生什么?假设 target1 是默认值,您的代码将如下所示:
<RouteRule name="routeToTarget2">
<Condition>thetype == "xyz"</Condition>
<TargetEndpoint>target2</TargetEndpoint>
</RouteRule>
<RouteRule name="routeToTarget1">
<TargetEndpoint>target1</TargetEndpoint>
</RouteRule>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)