request

Sends an HTTP request.

Syntax

Signature
request(Options: table) -> HttpResponse

Aliases

  • http_request
  • http.request
  • http.http_request

Parameters

ParameterTypeDescription
OptionstableUrl, optional Method, Body, Headers, and Cookies. Methods are GET, HEAD, POST, PUT, DELETE, OPTIONS, and PATCH.

Returns

TypeDescription
HttpResponseResponse table with Success, StatusCode, StatusMessage, Headers, and binary-safe Body.

Notes

Options.Url is required. Method defaults to GET, Body defaults to an empty string, and Headers and Cookies are optional string-to-string tables. The response contains Success, StatusCode, StatusMessage, Headers, and Body. Success is true for status codes from 200 through 299. Transport and validation failures raise errors. HTTP error statuses are returned in the response.

Request bodies and responses are limited to 16 MiB. URLs are limited to 65,536 bytes and headers plus cookies to 64 KiB. Only HTTP and HTTPS are accepted.

Example

Luau
local Response = request({
    Url = "https://httpbin.org/post",
    Method = "POST",
    Headers = {["Content-Type"] = "application/json"},
    Body = json.encode({message = "Hello"}),
})

if Response.Success then
    local Data = json.decode(Response.Body)
    print(Data.json.message)
else
    warn(Response.StatusCode, Response.StatusMessage)
end