Skip to main content

HTTP

http is the async HTTP client global. Backed by reqwest with rustls + json + socks features — same plumbing the licensing layer uses, so requests can hit https + socks5 transparently. Every call yields the script until the round-trip completes (or the timeout fires).

local res = http.get("https://api.example.com/data")
print(res.status, res.ok, res.body)

Request options

Every method takes the URL plus an optional HttpRequestOpts table. All fields are optional — pass nil/missing to use the default.

KeyTypeDefaultNotes
headers{[string]: string}?Custom request headers. Last value wins on duplicates.
bodystring?Raw body string. Mutually exclusive with json (json wins if both set).
jsonany?JSON-serialize the value, set Content-Type: application/json, send as body.
timeoutnumber?30000Per-request timeout in milliseconds.

Response shape

Every http.* call returns an HttpResponse table. The body is always read to completion as a string — there's no streaming variant.

FieldTypeNotes
statusnumberHTTP status as an integer (200, 404, 500, …).
okbooleantrue when status is 2xx, false otherwise.
bodystringResponse body as a UTF-8 string. Empty when the response carried no body.
headers{[string]: string}Response headers as a flat table. Last-value-wins on duplicates.

Methods

http:get(url, opts?)

FieldType
Signature(self: Http, url: string, opts: HttpRequestOpts?) → HttpResponse
ReturnsHttpResponse — see shape above
Common errorsraises on bad URL, network failure, timeout, or invalid json arg
Asyncyes — yields until the response completes or the timeout fires
local res = http.get("https://api.example.com/users", {
headers = { ["Authorization"] = "Bearer xxx" },
timeout = 5000,
})
if res.ok then
print(res.body)
end

http:post(url, opts?)

FieldType
Signature(self: Http, url: string, opts: HttpRequestOpts?) → HttpResponse
ReturnsHttpResponse — see shape above
Common errorsraises on bad URL, network failure, timeout, or invalid json arg
Asyncyes — yields until the response completes or the timeout fires
local res = http.post("https://discord.com/api/webhooks/...", {
json = { content = "bot online" },
headers = { ["Content-Type"] = "application/json" },
timeout = 10000,
})
print(res.status)

http:put(url, opts?)

FieldType
Signature(self: Http, url: string, opts: HttpRequestOpts?) → HttpResponse
ReturnsHttpResponse — see shape above
Common errorsraises on bad URL, network failure, timeout, or invalid json arg
Asyncyes — yields until the response completes or the timeout fires
http.put("https://api.example.com/users/42", {
json = { name = "renamed" },
})

http:delete(url, opts?)

FieldType
Signature(self: Http, url: string, opts: HttpRequestOpts?) → HttpResponse
ReturnsHttpResponse — see shape above
Common errorsraises on bad URL, network failure, timeout, or invalid json arg
Asyncyes — yields until the response completes or the timeout fires
http.delete("https://api.example.com/users/42")

See also

  • JSON — pair with http to encode/decode bodies cleanly