request Asynchronous

  • http.request
  • http_request
  • syn.request

Make an HTTP request and inspect the full response, including status, headers, and body. Use this for APIs that need methods other than GET or require request headers.

Syntax
Luau
request(options: HttpRequestOptions) -> HttpResponse

Parameters

Function parameters
ParameterTypeDescription
optionsHttpRequestOptionsTable containing Url and optional Method, Headers, Body, and Cookies.

Argument fields

HttpRequestOptions fields
Luau
HttpRequestOptions = {
  Url: string, Method: string?, Body: string?,
  Headers: {[string]: string}?, Cookies: {[string]: string}?
}
FieldDescription
UrlRequired HTTP or HTTPS URL.
MethodDefaults to GET. Accepted methods are GET, HEAD, POST, PUT, DELETE, OPTIONS, and PATCH; case is normalized.
BodyOptional body string. Serialize tables before assigning this field.
HeadersOptional map of HTTP header names to string values.
CookiesOptional map of cookie names to string values, sent with this request.

Returns

HttpResponse

An HttpResponse record with Success, StatusCode, StatusMessage, Headers, and Body.

HttpResponse fields
Luau
HttpResponse = {
  Success: boolean, Body: string, StatusCode: number,
  StatusMessage: string, Headers: {[string]: string}
}
FieldDescription
SuccessWhether the returned HTTP status indicates success.
BodyComplete response contents as a string, after supported HTTP content decoding. JSON parsing remains the caller’s responsibility. Oversized or invalid encoded responses raise instead of returning partial contents.
StatusCodeNumeric HTTP response status.
StatusMessageText describing the response status.
HeadersMap of response header names to values. There is no separate Cookies field.

Usage notes

Method defaults to GET in Kawaii. Set Body to a string; JSON payloads need json.encode and a matching Content-Type header.

HTTP error statuses return a response with Success=false. Transport, decode, and resource-limit failures raise an error instead, so use pcall if the request is optional.

Limits

ResourceLimitWhat happens
Response body8 MiB of wire data and 8 MiB at each decoding stageThe call raises an error when any stage exceeds the limit. It does not return a truncated body.
Content encodingUp to 3 encoding layers; 16 MiB of cumulative decoded outputgzip, deflate, and identity are supported. Unsupported encodings or an exhausted decoding budget raise an error.
Concurrent response readers4 across the processAn additional response read fails immediately while all readers are busy. This is not a four-request limit.
Transport deadlines30 seconds to connect, 60 seconds for a read, 90 seconds totalA timeout raises an error. A per-request Timeout option is not supported.

Catch transport and decoding errors with pcall. These limits cover response data held by the transport, not the total memory used by your script. A successful response must still be checked for the HTTP status you expected.

Differences from sUNC

Kawaii defaults Method to GET when it is omitted or nil. The sUNC request type declares Method as required. Explicit method names are normalized to uppercase.

Example

Example
Luau
local ok, response = pcall(request, {
    Url = "https://example.com/",
    Method = "GET",
})
if not ok then
    warn("Could not reach server:", response)
elseif response.Success then
    print(response.StatusCode, response.Body)
else
    warn(response.StatusCode, response.StatusMessage)
end
Kawaii documentation