Sample code for 30+ languages & platforms
Lianja

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

Lianja
llSuccess = .F.

loRest = createobject("CkRest")
llBTls = .T.
llBAutoReconnect = .T.
llSuccess = loRest.Connect("example.com",443,llBTls,llBAutoReconnect)
if (llSuccess = .F.) then
    ? loRest.LastErrorText
    release loRest
    return
endif

//  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.
loSbRequest = createobject("CkStringBuilder")
loSbRequest.Append('{ "query": "chilkat" }')

loRest.AddHeader("Content-Type","application/json")

loSbResponse = createobject("CkStringBuilder")
llSuccess = loRest.FullRequestSb("POST","/api/search",loSbRequest,loSbResponse)
if (llSuccess = .F.) then
    ? loRest.LastErrorText
    release loRest
    release loSbRequest
    release loSbResponse
    return
endif

lcResponseText = loSbResponse.GetAsString()
if (loSbResponse.LastMethodSuccess = .F.) then
    ? loSbResponse.LastErrorText
    release loRest
    release loSbRequest
    release loSbResponse
    return
endif

? lcResponseText


release loRest
release loSbRequest
release loSbResponse