http_get
http_get(url, [headers]) performs an HTTP GET request. Returns (response, nil) on success or (nil, error_table) on failure.
Signature
Section titled “Signature”http_get(url, [headers])
asyncParameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
url |
string | Target URL |
headers |
table? | Optional key-value header pairs |
Returns
Section titled “Returns”On success: (response, nil)
| Field | Type | Description |
|---|---|---|
status |
number | HTTP status code |
body |
string | Response body |
headers |
table | Response headers as key-value pairs |
url |
string | Final URL (after redirects) |
time_ms |
number | Request duration in milliseconds |
size |
number | Response body size in bytes |
On failure: (nil, error_table)
| Field | Type | Description |
|---|---|---|
error |
string | Human-readable error message |
kind |
string | Error kind: dns, timeout, proxy, tls, connect, size, http, or unknown |
proxy |
string? | Proxy URL that failed (only on proxy errors) |
Example
Section titled “Example”local res, err = http_get("https://api.example.com", { ["Authorization"] = "Bearer token123", ["X-Custom-Header"] = "my-value"})if not res then log("request failed: " .. err.error .. " (" .. err.kind .. ")") returnendSee Also
Section titled “See Also”- http_post - HTTP POST request
- http_request - Arbitrary HTTP request with proxy/timeout support
- http_multipart - Multipart form upload