One API proxy calling two different target endpoints

怎甘沉沦 提交于 2019-12-01 12:16:45
Mike Dunker

Check out the answer to this question. The details of finding the RouteRules is listed there. The ProxyEndpoint documentation will also be helpful.

You can accomplish what you are attempting using this code:

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

These RouteRules will be evaluated in order.

Note that you probably want the bottom RouteRule to have no condition, which means it will always match. What happens when thetype does not equal "abc" or "xyz"? Assuming target1 is the default, your code would look like this:

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

If you are using the API Proxy Editor UI, then you can do the following:

(1) Choose New / New Resource from the API Proxy Editor toolbar.

You will then see this:

(2) For the input field, Optional Target URL, enter the target URL that corresponds to that resource.

This tool will then generate both a conditional flow for that resource to which you can optionally attach resource-specific policies.

This tool will also add the needed route rule, and your generated XML will look like this:

<ProxyEndpoint name="default">
    <RouteRule name="Resource-1">
        <Condition>(proxy.pathsuffix MatchesPath &quot;/someResource&quot;) and (request.verb = &quot;GET&quot;)</Condition>
        <HTTPTargetConnection>
            <URL>http://myAlternateEndpoint</URL>
        </HTTPTargetConnection>
    </RouteRule>
    ....
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!