call different target connections based on query param

Not applicable

Hi ,

I need to call different target server paths based on incoming request query param value.

My incoming query param is "async" which will have either "true" or "false".

based on the async query value, i need to change path of target .

<HTTPTargetConnection>

<LoadBalancer>

<Server name="target-server"/>

</LoadBalancer>

<Path>/v1/sync/test</Path>

</HTTPTargetConnection>

if async=false

<Path>/v1/sync/test</Path>

if async=true

<Path>/v1/async/test</Path>

Thanks

0 2 270
2 REPLIES 2

umannggoel
Participant II

@Gopi Krishna M

You can do it , there are multiple options to do it.

1:Use java script - Store the query param value, compare it and set the path i.e make it dynamic

JS:
var q=context.getVariable("request.queryparam.async);
compare "q" value with true/false and set it
if(q==  "true")
context.setVariable(value,"v1/sync/test");
else
context.setVariable(value,"v1/async/test");


TargetServer:

<HTTPTargetConnection>
<LoadBalancer>
<Server name="target-server"/>
</LoadBalancer>
<Path>{value}</Path>
</HTTPTargetConnection>