Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Multiple proxy and target endpoints

Not applicable

I want to have the following API structure, with ONE ProxyEndpoint and 2 TargetEndpoints which I already have:

https://myapigeeurl/services/v1/product/quote map to <target>/api/quote-service

and

https://myapigeeurl/services/v1/product/ref-data map to <target>/api/reference-data-service

I understand that I can do that easily with TWO ProxyEndpoints and TWO Target Endpoints, but I would have to repeat the Pre and Post flows etc in each ProxyEndpoint and that's not nice as the whole process is the same.

The issue right now is since the base path in the ProxyEndpoint is set to /services/v1/product

And the route rules are configured like that:

<RouteRule name="Quote Service Rule">
  <Condition>(proxy.pathsuffix MatchesPath "/quote/**")</Condition>
  <TargetEndpoint>targetQuote</TargetEndpoint>
</RouteRule>
<RouteRule name="Reference Data Service Rule">
  <Condition>(proxy.pathsuffix MatchesPath "/ref-data/**")</Condition>
  <TargetEndpoint>targetRefData</TargetEndpoint>
</RouteRule>

With the TargetEndpoints setup like:

<TargetEndpoint name="targetQuote">
        <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="service-gateway"/>
        </LoadBalancer>
        <Path>/api/quote-service</Path>
    </HTTPTargetConnection>
</TargetEndpoint>
<TargetEndpoint name="targetRefData">
        <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="service-gateway"/>
        </LoadBalancer>
        <Path>/api/reference-data-service</Path>
    </HTTPTargetConnection>
</TargetEndpoint>

When I invoke:

https://myapigeeurl/services/v1/product/ref-data/stuff the target url invoked is <target>/api/reference-data-service/ref-data/stuff because the proxy.pathsuffix is obviously "ref-data/stuff"

How to strip that off? The target URL invoked should be <target>/api-reference-data/stuff

Many thanks in advance for your help.

Solved Solved
1 5 4,270
1 ACCEPTED SOLUTION

@Roman Rodov , Welcome to Apigee Community,

You can use shared flows if you don't want to repeat all the policies in different proxy endpoints. Optionally, You can override target url in target endpoint preflow using javascript policy like below,

context.setVariable("target.copy.pathsuffix", false);
var proxySuffix = context.getVariable("proxy.pathsuffix");
var proxySuffixFragments = proxySuffix.split("/");
var targetpathsuffix = proxySuffixFragments.splice(2).join("/");
context.setVariable("targetpathsuffix", targetpathsuffix);
<TargetEndpoint name="targetRefData">
        <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="service-gateway"/>
        </LoadBalancer>
        <Path>/api/reference-data-service/{targetpathsuffix}</Path>
    </HTTPTargetConnection>
</TargetEndpoint>

Hope it helps. Keep us posted moving forward if any.

View solution in original post

5 REPLIES 5