JavaScript
JavaScript
Use an Existing Socket Connection for REST
See more REST Examples
Demonstrates Rest.UseConnection, which supplies an already-connected Socket as the transport for REST requests instead of calling Connect. This is useful when the connection must be established with specific socket options or shared across objects.
Background. Rest can operate over any connected socket. The second argument enables automatic reconnection so a dropped connection is transparently re-established between requests.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// Demonstrates supplying an already-connected socket for the REST transport. This is useful when
// the connection must be established with specific socket options, or reused across objects.
var socket = new CkSocket();
var bSsl = true;
success = socket.Connect("example.com",443,bSsl,5000);
if (success !== true) {
console.log(socket.LastErrorText);
return;
}
var rest = new CkRest();
// Use the connected socket as the transport. The 2nd argument enables automatic reconnection.
var bAutoReconnect = true;
success = rest.UseConnection(socket,bAutoReconnect);
if (success == false) {
console.log(rest.LastErrorText);
return;
}
var responseText = rest.FullRequestNoBody("GET","/api/status");
if (rest.LastMethodSuccess == false) {
console.log(rest.LastErrorText);
return;
}
console.log(responseText);