Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoRest
    Boolean iBTls
    Boolean iBAutoReconnect
    Variant vSbRequest
    Handle hoSbRequest
    Variant vSbResponse
    Handle hoSbResponse
    String sResponseText
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End
    Move True To iBTls
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "example.com" 443 iBTls iBAutoReconnect To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    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.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequest
    If (Not(IsComObjectCreated(hoSbRequest))) Begin
        Send CreateComObject of hoSbRequest
    End
    Get ComAppend Of hoSbRequest '{ "query": "chilkat" }' To iSuccess

    Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse
    If (Not(IsComObjectCreated(hoSbResponse))) Begin
        Send CreateComObject of hoSbResponse
    End
    Get pvComObject of hoSbRequest to vSbRequest
    Get pvComObject of hoSbResponse to vSbResponse
    Get ComFullRequestSb Of hoRest "POST" "/api/search" vSbRequest vSbResponse To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComGetAsString Of hoSbResponse To sResponseText
    Get ComLastMethodSuccess Of hoSbResponse To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoSbResponse To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sResponseText


End_Procedure