0

In my API i am having two resources.One resource uses the default target end point.Where as for the other resource I don't want it to route to the default target. So I have given no route.But it is still getting routed to the default target.can anyone please help me with this.

Hitesh
  • 3,449
  • 8
  • 39
  • 57

2 Answers2

0

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>
Community
  • 1
  • 1
Vinit Mehta
  • 189
  • 2
0

A couple of additional points:

(1) You don't have to create a entire additional target endpoint if you don't need the full power of a discrete target endpoint. There is a lighter-weight option that you can choose to use, where you simply route directly to a supplied URL - rather than via a target endpoint. It looks like this:

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

(2) If you use the management UI (edge.apigee.com), the UI will write the conditional flow and route rule simultaneously when you use the New Resource dialog tool.

The dialog looks like this: enter image description here

It will generate this:

<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>
Randy Solton
  • 364
  • 1
  • 3