request Asynchronous
http.requesthttp_requestsyn.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.
request(options: HttpRequestOptions) -> HttpResponseParameters
| Parameter | Type | Description |
|---|---|---|
options | HttpRequestOptions | Request settings. Url is required; the other fields are described below. |
Argument fields
HttpRequestOptions = {
Url: string, Method: string?, Body: string?,
Headers: {[string]: string}?, Cookies: {[string]: string}?
}| Field | Description |
|---|---|
Url | Required HTTP or HTTPS URL. |
Method | Defaults to GET. Accepted methods are GET, HEAD, POST, PUT, DELETE, OPTIONS, and PATCH; case is normalized. |
Body | Optional body string. Serialize tables before assigning this field. |
Headers | Optional map of HTTP header names to string values. |
Cookies | Optional map of cookie names to string values, sent with this request. |
Returns
HttpResponseAn HttpResponse record. Check Success or StatusCode before using Body; receiving a response does not mean the server accepted the request.
HttpResponse = {
Success: boolean, Body: string, StatusCode: number,
StatusMessage: string, Headers: {[string]: string}
}| Field | Description |
|---|---|
Success | Whether the returned HTTP status indicates success. |
Body | Response contents as a string; decode it separately if it contains JSON. |
StatusCode | Numeric HTTP response status. |
StatusMessage | Text describing the response status. |
Headers | Map 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
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