util.http.post

Shared

Executes a POST request on specified url


Syntax

local promise = util.http.post(
    url,
    body,
    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.post(...)) 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
stringbodyRequest body for 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 POST request with a JSON body
util.thread.create(function(self)
    local ok, result = self:await(util.http.post("https://api.example.com/users",
        util.table.encode({
            name = "John Doe",
            email = "john@example.com"
        })
    ))

    if ok then
        core.engine.print("info", "Response:", result)
    else
        core.engine.print("error", "Request failed:", result)
    end
end):resume()
Send a POST with custom authorization header and timeout
util.thread.create(function(self)
    local ok, result = self:await(util.http.post("https://api.example.com/users",
        util.table.encode({
            name = "John Doe",
            email = "john@example.com"
        }),
        {
            "Authorization: Bearer my-token"
        },
        30
    ))

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

On this page