client
luau
local client = require("@lute/net/client")WARNING
These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.
Summary
| Entry | Description |
|---|---|
| Metadata | HTTP request metadata, including optional method, body, and headers. |
| Response | An HTTP response, containing status code, headers, body, and a success flag. |
| WebSocket | A client-side WebSocket connection handle. |
| WebSocketOptions | Options for establishing a WebSocket connection, including optional event handlers. |
| request | Makes an HTTP request to url with optional request metadata. Returns the response. |
| websocket | Opens a WebSocket connection to url. Returns a WebSocket handle. |
Types
Metadata
HTTP request metadata, including optional method, body, and headers.
luau
type Metadata = {
method: string?,
body: string?,
headers: { [string]: string }?,
}Response
An HTTP response, containing status code, headers, body, and a success flag.
luau
type Response = {
body: string,
headers: { [string]: string },
status: number,
ok: boolean,
}WebSocket
A client-side WebSocket connection handle.
luau
type WebSocket = {
send: (self: WebSocket, data: string | buffer) -> (),
close: (self: WebSocket) -> (),
}WebSocketOptions
Options for establishing a WebSocket connection, including optional event handlers.
luau
type WebSocketOptions = {
headers: { [string]: string }?,
onopen: (() -> ())?,
onmessage: ((message: string | buffer) -> ())?,
onclose: ((code: number, reason: string) -> ())?,
onerror: ((error: string) -> ())?,
}Functions and Properties
client.request
Makes an HTTP request to url with optional request metadata. Returns the response.
luau
(url: string, metadata: Metadata?) -> Responseclient.websocket
Opens a WebSocket connection to url. Returns a WebSocket handle.
luau
(url: string, options: WebSocketOptions?) -> WebSocket