【问题标题】:No-Route for a resource in APIGEEAPIGEE 中资源的无路由
【发布时间】:2014-06-26 18:00:33
【问题描述】:

在我的 API 中,我有两个资源。一个资源使用默认目标端点。至于其他资源,我不希望它路由到默认目标。所以我没有给出路由。但它仍然被路由到默认目标。任何人都可以帮我解决这个问题。

【问题讨论】:

  • 请分享配置。知道这个信息很容易回答问题。

标签: api apigee


【解决方案1】:

查看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 没有条件,这意味着它将始终匹配。当类型不等于“abc”或“xyz”时会发生什么?假设 target1 是默认值,您的代码将如下所示:

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

【讨论】:

    【解决方案2】:

    补充几点:

    (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),当您使用 New Resource 对话框工具时,UI 会同时编写条件流和路由规则。

    对话框如下所示:

    它会生成这个:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      相关资源
      最近更新 更多