My requirement is quite simple.I am sending a request url ‘http://apitechbasics-test.apigee.net/conditionalroutingwithdynamicendpoint ’ which is my proxy endpoint url .I will add one variable to request url ‘http://apitechbasics-test.apigee.net/conditionalroutingwithdynamicendpoint/13 ’ ,the value ‘13’ needs to picked up by ‘extractvariable’ or ‘assignmessage’ policy and prepare target request based this value.Desired target url is ‘http://www.thomas-bayer.com/sqlrest/CUSTOMER/13 ’.
I have used below policies at the Target endpoint request flow and tried to call backend .My requirement is clear ,but I am not able to create complete code for this .
Here is the desinged code.
API proxy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> /conditionalroutingwithdynamicendpoint 1477473512324 nvraghavendra254@gmail.com ConditionalRoutingwithDynamicEndpoint 1477487807086 nvraghavendra254@gmail.com Assign-Message-1 GetZipCode default jsc://JavaScript-1.js default false
Extract variable:GetZipCode
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> GetZipCode /{pathSeg}
request getcityforecastbyzip
Assign message:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Assign Message-1 target.url http://apitechbasics-test.apigee.net/conditionalroutingwithdynamicendpoint/{id} true
My implementation might be wrong ,please suggest me the appropriate way to acheive my requirement.
Hi @veeraraghavendra ,
Scenario 1 - Assuming the base path be ‘/’
<Pattern ignoreCase="true">/conditionalroutingwithdynamicendpoint/{zipcode}</Pattern>
Scenario 2 - Assuming the base path be ‘/conditionalroutingwithdynamicendpoint’
<Pattern ignoreCase="true">/{zipcode}</Pattern>
Extract Variable Policy - Assuming Scenario 2 - the uri param is extracted to a flow variable called zipcode
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="true" enabled="true" name="GetZipCode">
<DisplayName>GetZipCode</DisplayName>
<URIPath name="zipcode">
<Pattern ignoreCase="true">/{zipcode}</Pattern>
</URIPath>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>
Javascript Policy - Assign target.url
//get zipcode value already extracted
var zipcode=context.getVariable("zipcode");
//frame target_url
var target_url="http://www.thomas-bayer.com/sqlrest/CUSTOMER/"+zipcode;
//assign to target.url flow variable
context.setVariable("target.url",target_url);
Following is the issue with Assign Message Policy you have used -
tag is used to specify the source variable.
http://apitechbasics-test.apigee.net/conditionalroutingwithdynamicendpoint/{id} as a whole,having not found as a variable fails to assign the value.
tag is used to specify the value directly, no substitution occurs here. Hence, http://apitechbasics-test.apigee.net/conditionalroutingwithdynamicendpoint/{id} is directly set as target.url and {id} is not replaced
<AssignVariable>
<Name>target.url</Name>
<Value>http://apitechbasics-test.apigee.net/conditionalroutingwithdynamicendpoint/{id}</Value>
<Ref>http://apitechbasics-test.apigee.net/conditionalroutingwithdynamicendpoint/{id}</Ref>
</AssignVariable>
Hope this works, thank you!
Thanks for your help,let me try this way
Hi Nisha,
Many thanks for helping me on this .It is working now ,
Thanks Again
anilsr
October 28, 2016, 10:59am
5
@Nisha Mallesh , Great answer, Just FYI, use code button in editor to beautify code instead of table border.
@Anil Sagar Thanks, Yes I have started using them, in my latest posts.