Rest
rest.post
Shared
Executes a POST request on specified url
Syntax
local response, error = rest.post(url, body, headers = {
"Content-Type: application/json"
}, 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 |
string | body | Request body for 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.post(
"https://api.example.com/users",
table.encode({
name: "John Doe",
email: "john@example.com"
}, "JSON")
)
engine.print("info", "Response:", response, errorcode)
end):resume()thread:create(function(self)
local response, errorcode = rest.post(
"https://api.example.com/users",
table.encode({
name: "John Doe",
email: "john@example.com"
}, "JSON"),
{
"Authorization: Bearer my-token"
},
30
)
engine.print("info", "Response:", response, errorcode)
end):resume()