API reference
httpLua table
Make asynchronous web requests from a module.
The http table queues HTTP or HTTPS requests. URLs are at most 2048 bytes, responses at most 64 KiB, and requests time out after 10 seconds. A loaded module receives the result in on_http(requestId, status, body, error).
http.get(url)
Parameters: url is an HTTP or HTTPS URL. Returns: A numeric request ID when queued, or nil, error. Queueing does not mean the request succeeded.
local requestId, err = http.get("https://example.com/")
if not requestId then log.warn(err) endhttp.post(url, body)
Parameters: url follows the same URL rule. body is a string of at most 64 KiB. Returns: A numeric request ID when queued, or nil, error.
local requestId, err = http.post("https://example.com/api", "hello")
if not requestId then log.warn(err) endResponse callback
on_http(requestId, status, body, error) receives the matching request ID, response status, response text, and error text.
function on_http(requestId, status, body, error)
if error ~= "" then
log.warn(error)
else
log.info(string.format("Request %d returned %d", requestId, status))
end
end