Skip to content

network

The network namespace provides raw HTTP request capabilities for communicating with web APIs.


When a callback function is provided:

  • The request is dispatched non-blockingly and polled once per frame.
  • The callback receives body: string | nil when the response lands.
  • In-flight requests are automatically discarded if the script is unloaded before response arrival.

-- Synchronous (Blocking)
local body = network.get(url: string, headers?: table) --> string | nil
-- Asynchronous (Non-Blocking)
network.get(url: string, headers?: table, callback: function) --> nil
-- Synchronous (Blocking)
local body = network.request(method: string, url: string, options?: table) --> string | nil
-- Asynchronous (Non-Blocking)
network.request(method: string, url: string, options?: table, callback: function) --> nil

Supported HTTP methods: "GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS".


Field Type Description
headers table Map of key-value header strings (e.g. { ["Authorization"] = "Bearer token" }).
params table Form-encoded query parameters appended to URL.
body string | table Raw payload string or table (form-encoded or JSON).
content_type string Defaults to "application/x-www-form-urlencoded". Set to "application/json" for JSON.
network_timeout number Inactivity timeout in seconds.
absolute_timeout number Total request timeout in seconds (default: 1s sync, 15s async).

local payload = {
user = "Player1",
score = 1500
}
network.request("POST", "https://api.example.com/v1/scores", {
headers = { ["Authorization"] = "Bearer secret_api_token" },
content_type = "application/json",
body = json.stringify(payload)
}, function(body)
if body then
print("Score submitted successfully: " .. body)
else
print("Network request failed or timed out.")
end
end)