Is is possible to set proxy path suffix dynamically ?

Hello ApiGeeks,

I got a scenario to which i want to set proxy path-suffix dynamically,so that request must pass through conditional flow.Below is detail;

1.The client is making a call to a proxy without path suffix, due to which the call is not flowing through conditional flow.

2.Since there are multiple conditional flow, the call should pass through any of this flow based on parameter present in request content.For instance , if the request content contains a parameter as placeOrder the proxy suffix path should set to same.By doing this the call must pass through any of the conditional flow.

3.To achieve this i tried using JS but no fruit. Below is the code:

var json = JSON.parse(context.getVariable("request.content"));
var action = json.result.action;
var path = context.getVariable("proxy.pathsuffix");
if(action == 'placeOrder'){
context.setVariable("proxy.pathsuffix", '/'+action);
}else if(action == 'ViewSingleProduct'){
context.setVariable("proxy.pathsuffix", '/'+action);
}

Attached trace snap.screenshot-112.png.

Any idea how to make this ?Is it really possible to set proxy path-suffix dynamically.Appreciate you help.

Thanks you,

KP

0 10 4,668
10 REPLIES 10

sidd-harth
Participant V

Hi @Karthik Prabhu, AFAIK proxypath need to be static.

In your case since your making a call to a proxy without path suffix, the Apigee router cannot find the API proxy and hence it cannot run the conditional flows within the proxy.

For dynamic content try the below example, please let me know if it works,

You can have any proxypath as - '/path' for your proxy, it listen for anything /path/**

You can create conditional flows within it like /*/xyz which can handle all parameters like placeOrder & others as per conditions.

Hello @Barahalikar Siddharth,

--You can have any proxypath as - '/path' for your proxy, it listen for anything /path/**

Do you mean i have to add /path in baseurl ?

--- You can create conditional flows within it like /*/xyz

Could you please elborate on this, actually i didnt get you .

Thanks for your support,

KP

Hello @Barahalikar Siddharth

At present, i had implemented below Sean's logic but i am looking is it possible to achieve above one.Please do let me know.


Thanks,

Karthik

You don't have to use proxy.pathsuffix as the <Condition> in a conditional flow. You can use any variable you like. This way, you can do something like...

//Javascript Callout running in PreFlow

/**
* whatever logic you like here here...
*/

if(something) {
	context.setVariable("my.flow", "a");
} 
else {
	context.setVariable("my.flow", "b");
}

and in your Proxy or Target Endpoint

<Flows>
	<Flow name="a">
		<Request/>
		<Response/>
		<Condition>my.flow = "a"</Condition>
	</Flow>
	<Flow name="b">
		<Request/>
		<Response/>
		<Condition>my.flow = "b"</Condition>
	</Flow>
</Flows>

Thanks, Sean

Thanks @Sean Davis, Will try and let you know.

Any geeks could you help me on this ?

Hi @Karthik Prabhu, proxy.pathsuffix is a read-only variable you cannot change this dynamically using Javascript call out or any other policy in Apigee.

I agree with @Sean Davis, that is the correct way to do a conditional flow based on request content. If you have a JSON payload use a javascript callout to set some flow variables, if you have an xml payload use an extract variable policy with XPath to extract payload parameters.

Hello @Mohammed Zuber,

I agree with you.The above logic suggested by @Sean Davis is working but do we have any alternative solution.?

Thanks,

Karthik

Hi @Karthik Prabhu - There may be an alternative approach, but I'd guess it would be some variation on what Sean suggested above. I think your original question was answered because proxy.pathsuffix is read-only.

A suggestion might be to close this thread by accepting the answer and posing a new question with more details about what you're looking for as an alternative to the above suggestion and why.

Best,

Will

I know its old thread but what i did was i set the variable via javascript {targetPathSuffix}, also set context.setVariable("target.copy.pathsuffix", false); then in target flow

<HTTPTargetConnection>
        <LoadBalancer>
            <Server name="xyz"/>
        </LoadBalancer>
        <Path>{targetPathSuffix}</Path>
    </HTTPTargetConnection>