HTTP
Web requests from server scripts, for example webhooks or external APIs.
PerformHttpRequest
Section titled “PerformHttpRequest”PerformHttpRequest(url, callback?, method?, data?, headers?, options?) --> integerSend a web request and get the answer in a callback. Server only.
| Parameter | Type | Description |
|---|---|---|
url |
string |
http:// or https:// address. Addresses in private networks and localhost are blocked unless the server operator allows them. |
callback (optional) |
fun(statusCode: integer, body: string?, headers: table<string, string>, errorData: string?) |
Called with the result. body is nil for errors; then errorData has the reason or the error body. |
method (optional) |
string |
GET (default), POST, PUT, PATCH, DELETE, HEAD or OPTIONS. |
data (optional) |
string |
Request body, at most 1 MB by default. |
headers (optional) |
table<string, string> |
Request headers. |
options (optional) |
{timeout: integer?} |
timeout in milliseconds (at most the server limit, 30 s by default). |
Returns
integer: ID of the request.
PerformHttpRequest('https://example.com/api/status', function(status, body, headers, err) if status == 200 then local data = json.decode(body) else print('request failed', status, err) endend, 'GET', '', { ['Accept'] = 'application/json' })Compared to FiveM: Same as in FiveM. At most 32 requests per resource at the same time, responses up to 16 MB.