Appearance
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_resulthttp.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): boolTypes
http_result
| Field | Type |
|---|---|
success | bool |
status | integer |
error | integer |
headers | table<string, string>[] |
body | integer[] |
text | string |
json | table |
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)