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
| Type | Name |
|---|---|
bool | success |
integer | status |
integer | error |
table<string, string>[] | headers |
integer[] | body |
string | text |
table | json |
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)