Vital.sandbox
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

TypeNameDescription
stringurlRequest URL to query
tableheadersRequest headers for query
inttimeoutRead timeout in seconds

Returns

TypeNameDescription
string / boolresponseResponse on successful execution, or false on failure
string / boolerrorfalse on successful execution, or error on failure

Examples

Send a basic GET request
thread:create(function(self)
    local response, errorcode = rest.get("https://api.example.com/info")

    engine.print("info", "Response:", response, errorcode)
end):resume()
GET with custom headers and timeout
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()

On this page