How to get the value of target.url variable when target servers are used?

Not applicable

In my API proxy, I am using the Target Servers to connect to different backend server based on the environment. But when I extract the target.url variable in the target request post flow the value is always null. Any idea how to resolve this?

5 6 2,633
6 REPLIES 6

Hi @bibin_kurian, you may not be be access target.url when using target servers, why do you want to read it?

if you need just for logging, did you try request.url?

Thanks,

@Mukundha Madhavan,

Thank you for your reply. Yes, I need target.url for logging purpose. I tried using request.url, it’s also null in the target endpoint request post flow.

ok i just did a quick test, for Target servers, the following variables are available in the 'Target Response' flow,

target.host

target.ip

request.path

using this I think you should be able to construct the full URL. Pls note it is at the 'Target Response' flow.

It looks like these aren't available in the Target Request Flow? It's not really that big of a deal but I'm getting target.host populated on the 'Target Response Flow' but not the 'Target Request Flow'

Is that correct?

Hi - when using target servers these values do not appear to be available in the target request flow.

This actually "broke" the "template" that we have offered our internal users to work around some logging issues which I have brought up in the past.

At the moment we have just removed some of the data from the logs - but that wont be accepted as a long term solution.

To get the value of the target URL sent to the backend, even when using a TargetServer, you need access the request.url (not the target.url) variable in the TARGET RESPONSE PREFLOW (flow hook location).

I know it seems odd, but I've tested this and incorporated into my shared flows for GetLogValues and Log.

// When in TARGET RESPONSE PREFLOW
context.setVariable( 'logging.target.request.url', context.getVariable('request.url'));