Skip to content

HTTP

Reference for the http API.

WARNING

The fetch function is blocking.

Functions

http.fetch

Fetch data from a URL.

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

http.fetch_async

Fetch data from a URL async.

lua
---@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

FieldType
successbool
statusinteger
errorinteger
headerstable<string, string>[]
bodyinteger[]
textstring
jsontable

Examples

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