HTTP

⚠️ Warning
The `fetch` function is blocking.

Functions

fetch

Fetch data from a URL.

---@param url string
---@param options { method: string, headers: table<string, string>[], body: string|integer[]|json }
function http.fetch(url, options): http_result

fetch_async

Fetch data from a URL async.

---@param url string
---@param options { method: string, headers: table<string, string>[], body: string|integer[]|json }
---@param callback function(http_result)
function http.fetch_async(url, options, callback): bool

Types

http_result

TypeName
boolsuccess
integerstatus
integererror
table<string, string>[]headers
integer[]body
stringtext
tablejson

Example

local result = http.fetch('https://pastebin.com/raw/kNAcSPLC', { method='GET' })
if result.success then
  print(result.text)
end

http.fetch_async('https://pastebin.com/raw/kNAcSPLC', { method='GET' }, function(data)
  print('data:' .. data.text)
end)