Sample code for 30+ languages & platforms
Unicode C

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.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkRestW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkRestW rest;
    BOOL bTls;
    BOOL bAutoReconnect;
    HCkStringBuilderW sbResponse;
    const wchar_t *responseText;

    success = FALSE;

    rest = CkRestW_Create();
    bTls = TRUE;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"example.com",443,bTls,bAutoReconnect);
    if (success == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    //  FullRequestNoBodySb sends a request with no body and stores the text response body in a
    //  StringBuilder.
    sbResponse = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/api/items/123",sbResponse);
    if (success == FALSE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkStringBuilderW_Dispose(sbResponse);
        return;
    }

    responseText = CkStringBuilderW_getAsString(sbResponse);
    if (CkStringBuilderW_getLastMethodSuccess(sbResponse) == FALSE) {
        wprintf(L"%s\n",CkStringBuilderW_lastErrorText(sbResponse));
        CkRestW_Dispose(rest);
        CkStringBuilderW_Dispose(sbResponse);
        return;
    }

    wprintf(L"%s\n",responseText);


    CkRestW_Dispose(rest);
    CkStringBuilderW_Dispose(sbResponse);

    }