Skip to content

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 ​

EntryDescription
MetadataHTTP request metadata, including optional method, body, and headers.
ResponseAn HTTP response, containing status code, headers, body, and a success flag.
WebSocketA client-side WebSocket connection handle.
WebSocketOptionsOptions for establishing a WebSocket connection, including optional event handlers.
requestMakes an HTTP request to url with optional request metadata. Returns the response.
websocketOpens 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?) -> Response

client.websocket ​

Opens a WebSocket connection to url. Returns a WebSocket handle.

luau
(url: string, options: WebSocketOptions?) -> WebSocket