Proxy - Nested routing going to different hosts

Not applicable

I have the following paths for example and I'm trying to route to the following hosts.

/products/{product_id}
-> Routes to products.herokuapp.com/products/{product_id}


/products/{product_id/related
-> Routes to related.herokuapp.com/products/{product_id/related

How do I do this with the proxy?

0 1 217
1 REPLY 1

@leon

Add two target endpoints to your API. Name one "related" and one "products", give them both the right url.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="products">
  <Description/>
  <PreFlow name="PreFlow"/>
  <Flows/>
  <PostFlow name="PostFlow"/>
  <HTTPTargetConnection>
  <URL>https://products.herokuapp.com</URL>
  </HTTPTargetConnection>
</TargetEndpoint>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="related">
  <Description/>
  <FaultRules/>
  <PreFlow name="PreFlow"/>
  <PostFlow name="PostFlow"/>
  <Flows/>
  <HTTPTargetConnection>
  <Properties/>
  <URL>https://related.herokuapp.com</URL>
  </HTTPTargetConnection>
</TargetEndpoint>

Then with the following routerules, you can route to the correct TargetEndpoint one based on the pathsuffix.

<RouteRule name="products">
    <TargetEndpoint>default</TargetEndpoint>
    <Condition>(proxy.pathsuffix MatchesPath "/products/{product_id}") and (request.verb = "GET")</Condition>
</RouteRule>
<RouteRule name="related">
    <TargetEndpoint>Related</TargetEndpoint>
    <Condition>(proxy.pathsuffix MatchesPath "/products/{product_id}/related") and (request.verb = "GET")</Condition>
</RouteRule>