Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

local rest = chilkat.Rest.new()
local bTls = true
local bAutoReconnect = true
local success = rest:connect("example.com", 443, bTls, bAutoReconnect)
if not success then
    print(rest.last_error_text)
    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.
local sbRequest = chilkat.StringBuilder.new()
sbRequest:append("{ \"query\": \"chilkat\" }")

rest:add_header("Content-Type", "application/json")

local sbResponse = chilkat.StringBuilder.new()
success = rest:full_request_sb("POST", "/api/search", sbRequest, sbResponse)
if not success then
    print(rest.last_error_text)
    return
end

local responseText = sbResponse:get_as_string()
if not sbResponse.last_method_success then
    print(sbResponse.last_error_text)
    return
end

print(responseText)