Skip to main content

HTTP

Module: _http

_http.Call is async, returns immediately. Result comes via callbacks when the request finishes (if ever)

-- definition
type httpArgs = {
url: string,
method: string,
body: string?,
headers: {[string]: string}?,
response: ((status: number, headers: string, content: string) -> nil)?,
err: (() -> nil)?,
}```

```lua
-- usage example
_http.Call({
url = "https://httpbin.org/get?foo=bar",
method = "GET", -- "GET","POST","PUT","PATCH","DELETE",...
body = '{"hello":"world"}', -- raw body only. No tables, use _json.Encode
headers = {
["Content-Type"] = "application/json",
blablaApi = "myUltraSecretApi"
},
response = function(status, respHeaders, content)
-- status: number (e.g. 200, 404, 418)
-- respHeaders: string (raw body, _json.Decode)
-- content: string (raw body, _json.Decode)
end,
err = function()
-- no args
end,
})
Call(Data: httpArgs)return(arg1: nil)
_http.Call(Data: httpArgs) -> arg1: nil
1