Sample code for 30+ languages & platforms
Lua

REST Auto Reconnect for Multiple Requests (dev.markitondemand.com)

See more REST Examples

Demonstrates how the autoReconnect argument to the Connect method is used.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local rest = chilkat.Rest.new()

-- This example demonstrates the usage of the autoReconnect argument to the Connect method.
-- When autoReconnect is on, subsequent REST method calls will automatically re-connect
-- if necessary, using the same information (domain/IP address, port number, and TLS).
local bTls = false
local port = 80
local bAutoReconnect = true
local success = rest:connect("dev.markitondemand.com", port, bTls, bAutoReconnect)

-- Get a stock quote:
success = rest:add_query_param("symbol", "AAPL")
local responseXml = rest:full_request_no_body("GET", "/MODApis/Api/v2/Quote")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

local xml = chilkat.Xml.new()
success = xml:load_xml(responseXml)
print("AAPL LastPrice: " .. xml:get_child_content("LastPrice"))

-- Get another stock quote.  If a new HTTP connection is required,
-- the REST object will automatically connect using the same parameters.
success = rest:add_query_param("symbol", "AMZN")
responseXml = rest:full_request_no_body("GET", "/MODApis/Api/v2/Quote")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

success = xml:load_xml(responseXml)
print("AMZN LastPrice: " .. xml:get_child_content("LastPrice"))