Sample code for 30+ languages & platforms
DataFlex

Add a Query Parameter from a StringBuilder

See more REST Examples

Demonstrates Rest.AddQueryParamSb, which adds or replaces a query parameter whose value is read from a StringBuilder. The 1st argument is the name and the 2nd is the StringBuilder.

Background. This variant is convenient when the parameter value has already been assembled in a StringBuilder, avoiding an extra conversion to a plain string.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoRest
    Boolean iBTls
    Boolean iBAutoReconnect
    Variant vSbValue
    Handle hoSbValue
    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

    //  Connect to the REST server.  The 3rd argument enables TLS (use True for HTTPS on port 443),
    //  and the 4th enables automatic reconnection if the connection is dropped between requests.
    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

    //  The parameter value can also be supplied from a StringBuilder.  The 1st argument is the name and
    //  the 2nd is the StringBuilder holding the value.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbValue
    If (Not(IsComObjectCreated(hoSbValue))) Begin
        Send CreateComObject of hoSbValue
    End
    Get ComAppend Of hoSbValue "chilkat rest" To iSuccess

    Get pvComObject of hoSbValue to vSbValue
    Get ComAddQueryParamSb Of hoRest "q" vSbValue To iSuccess

    Get ComFullRequestNoBody Of hoRest "GET" "/api/search" To sResponseText
    Get ComLastMethodSuccess Of hoRest To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sResponseText


End_Procedure