http
All HTTP calls are asynchronous.
options
headers: table<string, string>
data: string | nil
contentType: string | nil
asTable: boolean
saveToFile: string | nil
headers are sent as request headers. data and contentType are used by http.post. When asTable is true, table data is converted into URL-encoded form data. saveToFile writes the response body to disk and passes an empty string to the callback.
get
Performs a GET request. The callback receives status_code and data. status_code is false on request errors.
http.get("https://example.com", { headers = { ["x-test"] = "neverfair" } }, function(status, data)
if status == 200 then
print(data)
end
end)
post
Performs a POST request. contentType defaults to application/x-www-form-urlencoded.
http.post("https://example.com", { headers = { ["x-test"] = "neverfair" }, contentType = "application/json", data = "{\"value\":123}" }, function(status, data)
if status == 200 then
menu.notify("post ok")
end
end)