Hi @Dino-at-Google, @Dino
Concern: We are having only one resource path “/sample” with three different query parameters. Now before sending the request to the backend, the query parameter name must be updated.
Apigee Endpoint: <APG-Host_name>/v1/sample?size=10
Target Endpoint: <Target-Host_name>/v1/sample?teamSize=10 (Format backend is accepting)
Apigee Endpoint: <APG-Host_name>/v1/sample?height=14
Target Endpoint: <Target-Host_name>/v1/sample?teamHeight=14 (Format backend is accepting)
Apigee Endpoint: <APG-Host_name>/v1/sample?len=15
Target Endpoint: <Target-Host_name>/v1/sample?width=15 (Format backend is accepting)
Here we are mapping as shown below:
size == teamSize
height == teamHeight
len == width
What is the better approach to solve this? (waiting for the solution)
1 Like
Hi Ashwith,
there are two easy options that I can think of.
- Use AssignMessage for assign the new query parameters and then remove the same.
<Set>
<QueryParams>
<QueryParam name="teamSize">{request.queryparam.size}</QueryParam>
<QueryParam name="teamHeight">{request.queryparam.height}</QueryParam>
<QueryParam name="width">{request.queryparam.len}</QueryParam>
</QueryParams>
</Set>
<Remove>
<QueryParams>
<QueryParam name="size"/>
<QueryParam name="height"/>
<QueryParam name="len"/>
</QueryParams>
</Remove>
With this approach you will not get opportunity for doing conditional check for not sending the only one parameter at a time. you will send empty parameters as well.
- Using Java Script policy
context.setVariable("target.copy.queryparams", false);
if(context.getVariable("request.queryparam.size")){
context.setVariable("request.queryparam.teamsize", context.getVariable("request.queryparam.size"));
}
if(context.getVariable("request.queryparam.height")){
context.setVariable("request.queryparam.teamheight", context.getVariable("request.queryparam.height"));
}
if(context.getVariable("request.queryparam.len")){
context.setVariable("request.queryparam.width", context.getVariable("request.queryparam.len"));
}
With this you will send the parameters if you have it.
Based on your requirement you can choose.
Thanks,
G Ramya
1 Like