Dynamic Endpoint Proxy for Testing and Production

Not applicable

I am trying to have a proxy that will make calls to our staging environment if the endpoint is our Apigee test uri is used and to our production endpoint if the production uri is used.

First Question: Is this a bad design pattern to have this routing condition on our production endpoint?

We want this as it will enable us to test the full integration before deploying to production.

We already have a proxy, say:

 ourorg-prod.apigee.net/foo

It routes to:

 productionbackend.com/foo

However, we would like to have the proxy route:

 ourorg-test.apigee.net/foo 

To:

 stagingbackend.com/foo

I have played around with TargetServers - one of the main issues I have had is trying to get stagingbackend.com/foo (full URI) as the target server. It works if its just stagingbackend.com, but when I try to add the additional portion of the URI it breaks (and therefore I think it probably shouldn't be done this way. Probably designed just for the base uri to the target server).

Help is appreciated

Solved Solved
1 5 2,809
2 ACCEPTED SOLUTIONS

Not applicable

Hi Kevin,

To answer your first question, no this is not a bad pattern at all. You should be able to use the target server configuration for the hostname and port. It sounds like you have that part working. In the target configuration in the proxy, you can configure the path portion:

    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="productionbackend"/>
        </LoadBalancer>
        <Path>/foo</Path>
    </HTTPTargetConnection>

Hope this helps!

View solution in original post

adas
New Member

@kevin12

You can also try conditional route rule so that in the same proxy, you can dynamically route to different endpoints based on a condition:

Here's an example of conditional route rules:

<RouteRule name="test">

<Condition>(environment.name = "test")</Condition>

<HTTPTargetConnection>

<URL>http://test.mydomain.net</URL>

</HTTPTargetConnection>

</RouteRule>

<RouteRule name="prod">

<Condition>(environment.name = "prod")</Condition>

<HTTPTargetConnection>

<URL>http://prod.mydomain.net</URL>

</HTTPTargetConnection>

</RouteRule>

This would work if you have environments in the Apigee Edge named as prod and test. The apiproxy that is deployed to test environment would be routed to the test endpoint and likewise for prod.

View solution in original post

5 REPLIES 5

Not applicable

Hi Kevin,

To answer your first question, no this is not a bad pattern at all. You should be able to use the target server configuration for the hostname and port. It sounds like you have that part working. In the target configuration in the proxy, you can configure the path portion:

    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="productionbackend"/>
        </LoadBalancer>
        <Path>/foo</Path>
    </HTTPTargetConnection>

Hope this helps!

adas
New Member

@kevin12

You can also try conditional route rule so that in the same proxy, you can dynamically route to different endpoints based on a condition:

Here's an example of conditional route rules:

<RouteRule name="test">

<Condition>(environment.name = "test")</Condition>

<HTTPTargetConnection>

<URL>http://test.mydomain.net</URL>

</HTTPTargetConnection>

</RouteRule>

<RouteRule name="prod">

<Condition>(environment.name = "prod")</Condition>

<HTTPTargetConnection>

<URL>http://prod.mydomain.net</URL>

</HTTPTargetConnection>

</RouteRule>

This would work if you have environments in the Apigee Edge named as prod and test. The apiproxy that is deployed to test environment would be routed to the test endpoint and likewise for prod.

Not applicable

Super helpful, thank you

Not applicable

@arghya das @clatimer1 Thanks for the responses, I tried implementing both ways. Both work, though I am having an issue where the API is returning a 301 and then it is redirecting to my backend URI.

Is there a way to prevent this from happening?

If I am using a conditional route rule, as described by arghya das, what should I be using as my HTTPTargetConnection endpoint value?

I already looked into this answer, but I am not changing from http to https or vice versa.

http://stackoverflow.com/questions/21413096/apigee-proxy-seems-to-redirect-to-my-underlying-api

Your help is appreciated! Thanks

adas
New Member

@kevin12

To answer your first question, it would be a difficult without looking at the actual response, and what else you are doing in the proxy. When you do a curl directly to your backend URL, does it return a 301 there as well. If that's the case, it means your target is redirecting to some default page so please ensure you are specifying the correct target endpoints. Please remember, by default the apigee apiproxy appends any pathsuffix from the request to the target. So please ensure that's not causing the redirect.

About your second question, when you are using conditional route rules its usually a good practice to have a default route rule (one without a condition) where you specify the default target and then in your TargetEndpoint you can specify what URL it should go to.

Here's an example:

<RouteRule name="default">

<TargetEndpoint>default</TargetEndpoint>

</RouteRule>

Put this at the very end of your route rule sequence so that this is triggered as the default route rule, if none of the others match.

The in your TargetEndpoint you can do:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<TargetEndpoint name="default">

<Description/>

<PreFlow name="PreFlow">

<Request/>

<Response/>

</PreFlow>

<Flows/>

<PostFlow name="PostFlow">

<Request/>

<Response/>

</PostFlow>

<HTTPTargetConnection>

<URL>http://default.mydomain.com</URL>

</HTTPTargetConnection>

</TargetEndpoint>

Or you can also you an inline target with the default route rule, like the conditional route rules. Hope this helps.