util.http.get

Shared

Executes a GET request on specified url


Syntax

local promise = util.http.get(
    url,
    headers = {
        "Content-Type: application/json"
    },
    timeout = 60
)

This function returns a promise and starts processing the query. Use thread:await inside a thread to retrieve the result.

  • Inside a threadself:await(util.http.get(...)) yields until the response is received, then returns the resolved values.
  • Outside a thread — the promise can still be created, but must be awaited from within a thread to retrieve the result.

Parameters

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

Returns

TypeNameDescription
promisepromiseRefer Settlements section

Settlements

TypeNameDescription
boolstatustrue on success, false otherwise
stringresolvedResponse body returned by the server
stringrejectedError message describing the failure

Examples

Send a basic GET request
util.thread.create(function(self)
    local ok, result = self:await(util.http.get("https://api.example.com/info"))
    
    if ok then
        core.engine.print("info", "Response:", result)
    else
        core.engine.print("error", "Request failed:", result)
    end
end):resume()
Send a GET with custom headers and timeout
util.thread.create(function(self)
    local ok, result = self:await(util.http.get("https://api.example.com/data",
        {
            "User-Agent: MyApp",
            "Accept: application/json"
        },
        30
    ))

    if ok then
        core.engine.print("info", "Response:", result)
    else
        core.engine.print("error", "Request failed:", result)
    end
end):resume()

On this page