request Asynchronous

  • http.request
  • http_request
  • syn.request

Send an HTTP request using a URL, method, and optional payload. The call waits for the response and returns its body, status, and headers together. Use it when a script needs to handle HTTP status codes, inspect headers, or send a body. Receiving a response and receiving a successful status are separate outcomes.

Syntax
Luau
request(options: HttpRequestOptions) -> HttpResponse

Parameters

Function parameters
ParameterTypeDescription
optionsHttpRequestOptionsRequest settings. Url is required; the other fields are described below.

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. Check Success or StatusCode before using Body; receiving a response does not mean the server accepted the request.

HttpResponse fields
Luau
HttpResponse = {
  Success: boolean, Body: string, StatusCode: number,
  StatusMessage: string, Headers: {[string]: string}
}
FieldDescription
SuccessWhether the returned HTTP status indicates success.
BodyResponse contents as a string; decode it separately if it contains JSON.
StatusCodeNumeric HTTP response status.
StatusMessageText describing the response status.
HeadersMap of response header names to values. There is no separate Cookies field.

Usage notes

Set Body to a string. For a JSON request, serialize the value with json.encode and supply a Content-Type header of application/json. Responses are not decoded automatically.

HTTP failures can return a response with Success=false. Invalid arguments and failures to start the request can raise an error. Use pcall if the caller needs to recover from either outcome.

The transport uses a 30-second connection timeout, a 60-second read timeout, and a 90-second total deadline. A per-request Timeout option is not implemented.

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/" })
if not ok then
    print("Request error:", response)
elseif response.Success then
    print(response.Body)
else
    print(response.StatusCode, response.StatusMessage)
end
Kawaii documentation