Rest
rest.get
Shared
Executes a GET request on specified url
Syntax
local response, error = rest.get(url, headers = {}, timeout = 60)Must be called within a valid thread context to operate asynchronously and without blocking execution.
- Inside a thread — runs asynchronously, yielding until the response is received
- Outside a thread — the request will not be processed and execution may stall
- Recommended usage — wrap calls in a coroutine or a thread spawned via your runtime's threading API
Parameters
| Type | Name | Description |
|---|---|---|
string | url | Request URL to query |
table | headers | Request headers for query |
int | timeout | Read timeout in seconds |
Returns
| Type | Name | Description |
|---|---|---|
string / bool | response | Response on successful execution, or false on failure |
string / bool | error | false on successful execution, or error on failure |
Examples
thread:create(function(self)
local response, errorcode = rest.get("https://api.example.com/info")
engine.print("info", "Response:", response, errorcode)
end):resume()thread:create(function(self)
local response, errorcode = rest.get(
"https://api.example.com/data",
{
"User-Agent: MyApp",
"Accept: application/json"
},
30
)
engine.print("info", "Response:", response, errorcode)
end):resume()