One API proxy calling two different target endpoints

前端 未结 2 1894
轻奢々
轻奢々 2021-01-16 07:03

i have just started working with Apigee. I want to create one API proxy which will call two target endpoints based on \'if\' condition. i have created an API and added resou

相关标签:
2条回答
  • 2021-01-16 07:17

    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: enter image description here

    (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>
        ....
    
    0 讨论(0)
  • 2021-01-16 07:33

    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>
    
    0 讨论(0)
提交回复
热议问题