Sample code for 30+ languages & platforms
JavaScript

Send a Bodyless REST Request into a StringBuilder

See more REST Examples

Demonstrates Rest.FullRequestNoBodySb, which sends a request with no body and stores the text response body in a StringBuilder.

Background. This variant of the no-body full request writes the response into a StringBuilder rather than returning it as a string, which is convenient when the response will be further processed in place.
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.
JavaScript
var success = false;

var rest = new CkRest();
var bTls = true;
var bAutoReconnect = true;
success = rest.Connect("example.com",443,bTls,bAutoReconnect);
if (success == false) {
    console.log(rest.LastErrorText);
    return;
}

//  FullRequestNoBodySb sends a request with no body and stores the text response body in a
//  StringBuilder.
var sbResponse = new CkStringBuilder();
success = rest.FullRequestNoBodySb("GET","/api/items/123",sbResponse);
if (success == false) {
    console.log(rest.LastErrorText);
    return;
}

var responseText = sbResponse.GetAsString();
if (sbResponse.LastMethodSuccess == false) {
    console.log(sbResponse.LastErrorText);
    return;
}

console.log(responseText);