Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 0

set rest [new_CkRest]

set bTls 1
set bAutoReconnect 1
set success [CkRest_Connect $rest "example.com" 443 $bTls $bAutoReconnect]
if {$success == 0} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

#  FullRequestNoBodySb sends a request with no body and stores the text response body in a
#  StringBuilder.
set sbResponse [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/api/items/123" $sbResponse]
if {$success == 0} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponse
    exit
}

set responseText [CkStringBuilder_getAsString $sbResponse]
if {[CkStringBuilder_get_LastMethodSuccess $sbResponse] == 0} then {
    puts [CkStringBuilder_lastErrorText $sbResponse]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponse
    exit
}

puts "$responseText"

delete_CkRest $rest
delete_CkStringBuilder $sbResponse