Network

Make HTTP requests and open WebSocket connections.

2 functionssUNC 100%Lynx 0.0.0

Lynx scripts can talk to any server on the internet, in any experience, whether or not the game has HTTP requests enabled.

HTTP

request

since 1.0.0Yields
request(options: RequestOptions): Response

Sends an HTTP request and yields until the response arrives.

Unlike HttpService, it also sends PUT, PATCH and DELETE and returns the full response, including status and headers, even when the server responds with an error. For a quick GET that only needs the body, game:HttpGet(url) also works.

Also available as http_request and http.request.

Parameters

optionsRequestOptions
What to send. See RequestOptions.

Returns

Response

The server's response. See Response.

Example

local HttpService = game:GetService("HttpService")
local response = request({
Url = "https://httpbin.org/post",
Method = "POST",
Headers = { ["Content-Type"] = "application/json" },
Body = HttpService:JSONEncode({ hello = "world" }),
})
print(response.StatusCode, response.StatusMessage) --> 200 OK
local data = HttpService:JSONDecode(response.Body)
print(data.json.hello) --> world

RequestOptions

Url
Typestring
The URL to request. Required.
Method
Typestring?
GET (the default), POST, PUT, PATCH or DELETE. Anything else raises an error.
Headers
Type{ [string]: string }?
Request headers. Send cookies with a Cookie header.
Body
Typestring?
The request body. Sent with POST, PUT and PATCH.

Response

Success
Typeboolean
true when StatusCode is between 200 and 299.
StatusCode
Typenumber
The HTTP status code.
StatusMessage
Typestring
The status text, such as "Not Found".
Headers
Type{ [string]: string }
Response headers.
Body
Typestring
The response body. Binary-safe.
Error
Typestring
What went wrong when the request itself failed. Empty otherwise.

Default headers

Lynx adds three headers to every request, so servers can tell Lynx traffic apart. A header of the same name in Headers replaces it.

HeaderValue
User-AgentLynx/1.0.
Lynx-FingerprintLynx's hardware ID for this PC. It's the same in every session and for every server you contact.
Lynx-User-IdentifierThe same hardware ID again, under the name some scripts expect.

WebSocket

WebSocket.connect

since 1.0.0Yields
WebSocket.connect(url: string): WebSocket

Opens a WebSocket connection to url and yields until it's established. Errors if the connection can't be made.

Parameters

urlstring
A ws:// or wss:// URL.

Returns

WebSocket

The open connection. See WebSocket object.

Example

local socket = WebSocket.connect("wss://echo.websocket.org")
socket.OnMessage:Connect(function(message)
print("received:", message)
end)
socket.OnClose:Connect(function()
print("closed")
end)
socket:Send("hello")
task.wait(2)
socket:Close()

WebSocket object

Send(message: string)
Kindmethod
Sends a text message.
Close()
Kindmethod
Closes the connection. OnClose fires.
OnMessage
Kindevent (message: string)
Fires for every message received.
OnClose
Kindevent ()
Fires once when the connection closes, from either side.