Skip to content

http

The http namespace provides an ergonomic HTTP client powered by ISteamHTTP that returns structured status codes, response headers, and success booleans.


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, response directly.
  • A function placed in the second parameter slot is treated directly as the callback: http.get(url, fn).

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.

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)