Sample code for 30+ languages & platforms
Lua

Simple GET using REST

See more REST Examples

Demonstrates how to do a simple HTTP GET request using REST.

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()

-- Connect to the REST server.
local bTls = true
local port = 443
local bAutoReconnect = true
local success = rest:connect("my-store.com", port, bTls, bAutoReconnect)

local responseJson = rest:full_request_no_body("GET", "/wp-json/wc/v1/products?consumer_key=YOUR_CONSUMER_KEY&consumer_secret=YOUR_CONSUMER_SECRET")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

print(responseJson)
print("----")

-- We can alternatively do this:
rest:clear_all_query_params()
rest:add_query_param("consumer_key", "YOUR_CONSUMER_KEY")
rest:add_query_param("consumer_secret", "YOUR_CONSUMER_SECRET")
responseJson = rest:full_request_no_body("GET", "/wp-json/wc/v1/products")
if not rest.last_method_success then
    print(rest.last_error_text)
    return
end

print(responseJson)