Lua
Lua
Use an Existing Socket Connection for REST
See more REST Examples
Demonstrates Rest.UseConnection, which supplies an already-connected Socket as the transport for REST requests instead of calling Connect. This is useful when the connection must be established with specific socket options or shared across objects.
Background. Rest can operate over any connected socket. The second argument enables automatic reconnection so a dropped connection is transparently re-established between requests.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Demonstrates supplying an already-connected socket for the REST transport. This is useful when
-- the connection must be established with specific socket options, or reused across objects.
local socket = chilkat.Socket.new()
local bSsl = true
local success = socket:connect("example.com", 443, bSsl, 5000)
if not success then
print(socket.last_error_text)
return
end
local rest = chilkat.Rest.new()
-- Use the connected socket as the transport. The 2nd argument enables automatic reconnection.
local bAutoReconnect = true
success = rest:use_connection(socket, bAutoReconnect)
if not success then
print(rest.last_error_text)
return
end
local responseText = rest:full_request_no_body("GET", "/api/status")
if not rest.last_method_success then
print(rest.last_error_text)
return
end
print(responseText)