Node.js
Node.js
Send a REST Request using StringBuilder Bodies
See more REST Examples
Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.
Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.
Chilkat Node.js Downloads
NODEJS_PRELUDE
function chilkatExample() {
var success = false;
var rest = new chilkat.Rest();
var bTls = true;
var bAutoReconnect = true;
success = rest.Connect("example.com",443,bTls,bAutoReconnect);
if (success == false) {
console.log(rest.LastErrorText);
return;
}
// FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
// response body in a second StringBuilder. This avoids extra string conversions for large bodies.
var sbRequest = new chilkat.StringBuilder();
sbRequest.Append("{ \"query\": \"chilkat\" }");
rest.AddHeader("Content-Type","application/json");
var sbResponse = new chilkat.StringBuilder();
success = rest.FullRequestSb("POST","/api/search",sbRequest,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);
}
chilkatExample();