http
The http namespace provides an ergonomic HTTP client powered by ISteamHTTP that returns structured status codes, response headers, and success booleans.
Functions
Section titled βFunctionsβhttp.get(url: string, options?: table, callback?: function)http.post(url: string, options?: table, callback?: function)http.request(method: string, url: string, options?: table, callback?: function)- When a callback is provided:
callback(success: boolean, response: table)is invoked when completed. - When no callback is provided: Blocks and returns
success, responsedirectly. - A function placed in the second parameter slot is treated directly as the callback:
http.get(url, fn).
Response Object
Section titled βResponse ObjectβThe response table passed to callbacks or returned contains:
| Property | Type | Description |
|---|---|---|
status |
number |
HTTP status code (e.g. 200, 404, 500). 0 if connection failed. |
body |
string |
Raw response body string. |
headers |
table |
Map of response headers (ETag, Last-Modified, Cache-Control, Content-Type, Content-Length, Location, Server, etc.). |
timed_out |
boolean |
true if request exceeded timeout threshold. |
request |
table |
Original request options. |
Example: Asynchronous API Request
Section titled βExample: Asynchronous API Requestβhttp.get("https://api.example.com/status", { params = { build = "nightly" }}, function(success, response) if not success or response.status ~= 200 then print(string.format("HTTP Error! Status: %d", response.status)) return end
local data = json.parse(response.body) print("API Status: " .. (data.message or "OK"))end)