@luisvillanueva1 ,
It’s not equal, I see it as a bug when it comes to runtime. Doc says,
Four child objects:proxyRequest, proxyResponse, targetRequest, targetResponse. These child objects are scoped to the ambient request and response, either the proxy request and response or the target request and response. For example, if theJavaScript policy executes in the proxy endpoint part of the flow, then the context.proxyRequest andcontext.proxyResponse objects are in scope. If the JavaScript runs in a target flow, then thecontext.targetRequest and context.targetResponse objects are in scope.
That means, When you attach the policy to one of the proxy / target request endpoints you can use context.proxyRequest.url , context.targetRequest.url respectively. That means, you cannot use context.targetRequest in proxy request & **context.proxyRequest.**url in target request. Ideally, It should print null if you use, but it prints same as of today. I see this as a bug in the system. I will let engineering team know about this.
What happens if you use, context.proxyRequest.url in proxy & context.targetRequest.url in target endpoints separate javascript policies ?
Let’s say,
Proxy URL is : http://anildevportal-test.apigee.net/mockjson
Target URL is : http://mocktarget.apigee.net/json
Then ,
context.proxyRequest.url outputs : **/mockjson (**Ideally , I expect , http://anildevportal-test.apigee.net/mockjson , which i see as an issue )
context.targetRequest.url outputs : http://mocktarget.apigee.net/json
See sample proxy below,
mockjson-rev2-2016-06-17.zip
Coming to your query,
You would need to construct proxy url in proxy request flow & assign to a custom flow variable, get target url from context.targetRequest.url in target request flow & assign to a custom flow variable. Use custom flow variables in target / proxy response flows to construct output content.
See attached proxy below which demonstrates same,
mockjson-rev3-2016-06-17.zip
Keep us posted if you have any queries. Hope it’s helpful.