How do I route to different Target Endpoints using JavaRegex

1 ACCEPTED SOLUTION

One way to do it is to have multiple targets, each with a different target endpoint. Then you'd have RouteRules, each with a distinct condition, that route to each of your different targets.

<RouteRule name='rule1'> 
  <Condition>(whatever you like here</Condition>
  <Target>target1</Target>
</RouteRule>
<RouteRule name='rule2'> 
  <Condition>(whatever you like here</Condition>
  <Target>target2</Target>
</RouteRule>
...

This seems to be heavyweight approach to the problem , especially if you've got numerous backend target URLs.

An alternative is to set the target.url variable within a JS callout. This must be done on the Target Request flow. The JS might look like:

var candidateUrls = [
  'https://apibaas-trial.apigee.net/shebababu92/sandbox/messengers',
  'https://apibaas-trial.apigee.net/shebababu92/sandbox/newmessengers',
 ];

if (some condition here) {
  context.setVariable('target.url', candidateUrls[0]);
}
else {
  context.setVariable('target.url', candidateUrls[1]);
}

View solution in original post

2 REPLIES 2

One way to do it is to have multiple targets, each with a different target endpoint. Then you'd have RouteRules, each with a distinct condition, that route to each of your different targets.

<RouteRule name='rule1'> 
  <Condition>(whatever you like here</Condition>
  <Target>target1</Target>
</RouteRule>
<RouteRule name='rule2'> 
  <Condition>(whatever you like here</Condition>
  <Target>target2</Target>
</RouteRule>
...

This seems to be heavyweight approach to the problem , especially if you've got numerous backend target URLs.

An alternative is to set the target.url variable within a JS callout. This must be done on the Target Request flow. The JS might look like:

var candidateUrls = [
  'https://apibaas-trial.apigee.net/shebababu92/sandbox/messengers',
  'https://apibaas-trial.apigee.net/shebababu92/sandbox/newmessengers',
 ];

if (some condition here) {
  context.setVariable('target.url', candidateUrls[0]);
}
else {
  context.setVariable('target.url', candidateUrls[1]);
}

Thank you so much .If I am using JS what condition I should give in Route rule?