Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
rest: HCkRest;
bTls: Boolean;
bAutoReconnect: Boolean;
sbRequest: HCkStringBuilder;
sbResponse: HCkStringBuilder;
responseText: PWideChar;

begin
success := False;

rest := CkRest_Create();
bTls := True;
bAutoReconnect := True;
success := CkRest_Connect(rest,'example.com',443,bTls,bAutoReconnect);
if (success = False) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

//  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.
sbRequest := CkStringBuilder_Create();
CkStringBuilder_Append(sbRequest,'{ "query": "chilkat" }');

CkRest_AddHeader(rest,'Content-Type','application/json');

sbResponse := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/api/search',sbRequest,sbResponse);
if (success = False) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

responseText := CkStringBuilder__getAsString(sbResponse);
if (CkStringBuilder_getLastMethodSuccess(sbResponse) = False) then
  begin
    Memo1.Lines.Add(CkStringBuilder__lastErrorText(sbResponse));
    Exit;
  end;
Memo1.Lines.Add(responseText);

CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbRequest);
CkStringBuilder_Dispose(sbResponse);