One API proxy calling two different target endpoints

Not applicable

Hi,

I have a requirement to create 1 API proxy but depending on the proxy pathsuffix I need to re-direct to different target endpoints...I have created target server to specify the server details...

How do I change the Path depending on the proxy suffix?

Below is how I call my target server...

<HTTPTargetConnection>
<SSLInfo>
<Enabled>true</Enabled>
<ClientAuthEnabled>true</ClientAuthEnabled>
<KeyStore>myKeystore</KeyStore>
<KeyAlias>myKeystore</KeyAlias>
</SSLInfo>
<LoadBalancer>
<Server name="Server"/>
</LoadBalancer>
<Path>/cxf/integration</Path>
</HTTPTargetConnection>

Thanks

0 5 3,994
5 REPLIES 5

hi @Deepa you may be refer this - https://community.apigee.com/questions/1326/specifying-proxy-endpoint.html, see @Dallen answer to handle proxy pathsuffix (in your case)

Hi Kuldeep...Thanks for coming back but the post you had pointed out is when we need to point to different Target server...but my requirement is Target server will be the same only the endpoint url will change depending on the proxy path

okay, I get it, I misread target endpoints with server!

Anyway, if you have one target server URL and you're doing one-to-one mapping with your endpoint then you just need to set once target URL;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>http://httpbin.org</URL>
    </HTTPTargetConnection>
</TargetEndpoint>
<br>

and as it is just pure proxying;

with that your path matches - http://{org}-{env}.apigee.net/{proxy_path}/status/404 = > http://httpbin.org/status/404

http://{org}-{env}.apigee.net/{proxy_path}/status/200 = > http://httpbin.org/status/200;

you do not need to put condition to match your proxy path as in this case no change in url pattern, as your apigee egde URL is mapped directly with your target endpoint;

In case you're rewriting edge URL; for e. g. http://{org}-{env}.apigee.net/{proxy_path}/HTTP/status/404, then you have to create a resource to filter out with condition; which is covered here in details - http://docs.apigee.com/api-services/content/uri-based-configurations

I hope this helps.

Hi,

To make myself clear...

I have specified my HTTP Target Connection as below which points to a TargetServer with name "Server" and Path as "<Path>/cxf/integrationXXX</Path>"

If I introduce condition flows in my proxy as

<HTTPTargetConnection>
<SSLInfo>
<Enabled>true</Enabled>
<ClientAuthEnabled>true</ClientAuthEnabled>
<KeyStore>myKeystore</KeyStore>
<KeyAlias>myKeystore</KeyAlias>
</SSLInfo>
<LoadBalancer>
<Server name="Server"/>
</LoadBalancer>
<Path>/cxf/integrationXXX</Path>

</HTTPTargetConnection>

If I use conditional flows one for GET and PUT requests as below .For both queries Target Server name is the same...but the path will be different say for GET Request Path will be "/user/getId" and for PUT request target path should be "user/create"

<Flows>

<Flow name="reports">

<Description/>

<Request>

<Step>XXXX</Step>

<Condition>(proxy.pathsuffix MatchesPath "/reports") and (request.verb = "GET")</Condition>

</Request>

<Response/>

</Flow>

<Flow name="reports">

<Description/>

<Request>

<Step>YYYY</Step>

<Condition>(proxy.pathsuffix MatchesPath "/reports") and (request.verb = "PUT")</Condition>

</Request>

<Response/>

</Flow>

hi @Deepa considering your use case there're multiple option to set target URL, with Assign Message Policy, using key map value using JavaScript policy, I would share the solution here with 2 Assign Message Policy...not recommended for upstream environment, as with Assign Message Policy you have to hard set target URL, there's no way to set it dynamically as far as I know, you can reference it via other Assign Message Policy but yet there also you have to set it first, and in this all your created Target Server in environment gets overridden.

For now, I have attached solution with Assign Message Policy, as said you can also use KVM.

I have used http://httpbin.org/get and http://httpbin.org/post for your GET and POST use case.

Also, there are multiple threads, you can read for your references;

https://community.apigee.com/questions/30443/how-to-access-targetserver-configuration-from-js-c.html

https://community.apigee.com/questions/30243/using-js-can-we-make-a-call-to-a-targetserver.html

https://community.apigee.com/questions/23928/get-target-host-details-when-using-targetserver-co.html

also, https://community.apigee.com/questions/4303/how-do-i-transform-the-path-between-the-proxy-and.html

IMO, for upstream where you have set of back end URL per environment(test, dev, uat, prod), better to create target server URL using key value map, explained here - https://community.apigee.com/questions/34760/how-to-set-target-url-with-a-keyvaluemap-property.html, that way you can control and manage your back-end server details and your API proxy will reference dynamically these run time.

let me know if this helps, good luck!