APIGEE资源的无路由

时间:2014-05-09 05:17:47

标签: api apigee

在我的API中,我有两个资源。一个资源使用默认目标端点。对于其他资源,我不希望它路由到默认目标。所以我没有给出任何路线。但是它仍然被路由到默认目标。任何人请帮助我。

2 个答案:

答案 0 :(得分:0)

查看this问题的答案。此处列出了查找RouteRules的详细信息。 ProxyEndpoint documentation也会有所帮助。

您可以使用此代码完成您尝试的操作:

<RouteRule name="routeToTarget1">
    <Condition>thetype == "abc"</Condition>
    <TargetEndpoint>target1</TargetEndpoint>
</RouteRule>
<RouteRule name="routeToTarget2">
    <Condition>thetype == "xyz"</Condition>
    <TargetEndpoint>target2</TargetEndpoint>
</RouteRule>

将按顺序评估这些RouteRules。

请注意,您可能希望底部RouteRule没有条件,这意味着它将始终匹配。当类型不等于&#34; abc&#34;或&#34; xyz&#34;?假设target1是默认值,您的代码将如下所示:

<RouteRule name="routeToTarget2">
    <Condition>thetype == "xyz"</Condition>
    <TargetEndpoint>target2</TargetEndpoint>
</RouteRule>
<RouteRule name="routeToTarget1">
    <TargetEndpoint>target1</TargetEndpoint>
</RouteRule>

答案 1 :(得分:0)

还有几点:

(1)如果您不需要离散目标端点的全部功能,则不必创建整个附加目标端点。您可以选择使用较轻的选项,只需直接路由到提供的URL - 而不是通过目标端点。它看起来像这样:

<RouteRule name="dog">
    <Condition>(proxy.pathsuffix MatchesPath "/dog") and (request.verb = "GET")</Condition>
    <HTTPTargetConnection>
        <URL>https://myOtherEndpoint.com</URL>
    </HTTPTargetConnection>
</RouteRule>

(2)如果您使用管理UI(edge.apigee.com),当您使用新资源对话框工具时,UI将同时编写条件流和路线规则。

对话框如下所示: enter image description here

它会产生这个:

<RouteRule name="dog">
    <Condition>(proxy.pathsuffix MatchesPath "/dog") and (request.verb = "GET")</Condition>
    <HTTPTargetConnection>
        <URL>https://myOtherEndpoint.com</URL>
    </HTTPTargetConnection>
</RouteRule>

<RouteRule name="default">
    <TargetEndpoint>default</TargetEndpoint>
</RouteRule>
相关问题