Using JS, can we make a call to a TargetServer

amar333n
Participant III

I have a TargetServer defined in Edge known as SoapServer. I want make a call to it using JS, is it possible?

Solved Solved
1 14 1,145
2 ACCEPTED SOLUTIONS

@Amar N , maybe, it's possible. SOAP is an XML-based encoding of messages that are typically sent over HTTP. So you can make a call. What have you tried ? Do you see any issues ?

But you cannot retrieve the TargetServer configuration from within a JS callout, if that's what you mean.

View solution in original post

No, you cannot.

You can *simulate* the behavior, by invoking the same HOST and URL as used in the TargetServer definition. But there's no good way to read the details of the TargetServer definition within the JS Callout.

Even if you simulate, it may not work properly. Does this TargetServer use client certificates?

I don't believe it is possible to do two-way ssl using the HTTP Client in Javascript callout. Instead, you will need to use a Service Callout or Node JS

View solution in original post

14 REPLIES 14

@Amar N , maybe, it's possible. SOAP is an XML-based encoding of messages that are typically sent over HTTP. So you can make a call. What have you tried ? Do you see any issues ?

But you cannot retrieve the TargetServer configuration from within a JS callout, if that's what you mean.

@Anil Sagar

I'm not sure how to retrieve the details of the target server in JS. Can you please help me regarding this.

I want to make a call using httpClient.send() functon to a targetServer.

See similar question asked here. Hope it helps. Keep us posted if any.

No, you cannot.

You can *simulate* the behavior, by invoking the same HOST and URL as used in the TargetServer definition. But there's no good way to read the details of the TargetServer definition within the JS Callout.

Even if you simulate, it may not work properly. Does this TargetServer use client certificates?

I don't believe it is possible to do two-way ssl using the HTTP Client in Javascript callout. Instead, you will need to use a Service Callout or Node JS

Thats my understanding as well

@Sean Davis

Thanks for the clarification.

Yes, the targetServer use the client certificates.

Node.JS would be your only other option.

Hope this helps!

Not applicable

We used node.js to make a call to the target server.

It's fairly easy to do with the help of request module, which is supported by default.

var request = require('request');

request('http://target_server_url', {

	qs: {'id':'123'}

}, function(error, result, body) {
    // call back function to process the response.
});

In either JavaScript or Nodejs, it is possible to send an outbound http message. I think the question here is specifically asking about a TargetServer, which is an entity in Edge that allows load-balancing across multiple backend endpoints.

I am also looking at this capability while building some new APIs. Is there a way to use Node to retrieve the TargetServer?

I don't think so. What do you really want to do? If you configure a TargetServer, the expectation is that the information there will be used by Edge for selection of the endpoint for the target. By reading it, what's your goal? Is the TargetServer mechanism itself not meeting your needs in some way?

Our team has imposed restrictions on us developers where they want to manage the connection centrally using some special security configuration. So, we need to reuse the shared configuration, which I don't have direct access to.

Ah, yes. Maybe you can store the configuration in:

  • KVM
  • BaaS

I have seen both used, to good effect. For KVM, the proxy would needs to read from the KVM before the JS executes. For BaaS, the JS can read. In either case though, you'd want to cache the results of the read so as not to be reading for every inbound request. That means you'd want a series of policies like this:

  • check cache for endpoint data
  • if not present read (from KVM or Baas)
  • insert read data into cache, TTL = ?? your choice
  • invoke JS policy, which selects an endpoint and invokes

Using this approach, it is also possible to do the weighted-random selection of targets in the JS itself. In other words, the JS might select from one of a set of target hosts. This is handy for enabling "blue/green" or "canary" deployments of backends.

rtalanki
Participant II

Here is sample code that will help to route the traffic to two different TargetServers. Uses RouteRule todo so.mytestproxy-rev1-2017-07-25.zip