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.
| Key | Type | Default | Notes |
|---|---|---|---|
headers | {[string]: string}? | — | Custom request headers. Last value wins on duplicates. |
body | string? | — | Raw body string. Mutually exclusive with json (json wins if both set). |
json | any? | — | JSON-serialize the value, set Content-Type: application/json, send as body. |
timeout | number? | 30000 | Per-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.
| Field | Type | Notes |
|---|---|---|
status | number | HTTP status as an integer (200, 404, 500, …). |
ok | boolean | true when status is 2xx, false otherwise. |
body | string | Response 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?)
| Field | Type |
|---|---|
| Signature | (self: Http, url: string, opts: HttpRequestOpts?) → HttpResponse |
| Returns | HttpResponse — see shape above |
| Common errors | raises on bad URL, network failure, timeout, or invalid json arg |
| Async | yes — 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?)
| Field | Type |
|---|---|
| Signature | (self: Http, url: string, opts: HttpRequestOpts?) → HttpResponse |
| Returns | HttpResponse — see shape above |
| Common errors | raises on bad URL, network failure, timeout, or invalid json arg |
| Async | yes — 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?)
| Field | Type |
|---|---|
| Signature | (self: Http, url: string, opts: HttpRequestOpts?) → HttpResponse |
| Returns | HttpResponse — see shape above |
| Common errors | raises on bad URL, network failure, timeout, or invalid json arg |
| Async | yes — yields until the response completes or the timeout fires |
http.put("https://api.example.com/users/42", {
json = { name = "renamed" },
})
http:delete(url, opts?)
| Field | Type |
|---|---|
| Signature | (self: Http, url: string, opts: HttpRequestOpts?) → HttpResponse |
| Returns | HttpResponse — see shape above |
| Common errors | raises on bad URL, network failure, timeout, or invalid json arg |
| Async | yes — yields until the response completes or the timeout fires |
http.delete("https://api.example.com/users/42")
See also
- JSON — pair with
httpto encode/decode bodies cleanly