HTTP¶
The HTTP library is used to send HTTP requests and open WebSocket connections.
Warning
HTTP must be enabled in the settings file!
Usage¶
| Lua | |
|---|---|
Functions¶
checkURL¶
http.checkURL( url )
Check whether the URL is valid and the protocol is either http, https, ws, or wss.
Parameters¶
url: string - The URL to check.
Returns¶
valid: boolean - Whether the URL is valid.
requestAsync¶
http.requestAsync( url, body?, headers?, options? )
Send an asynchronous HTTP request.
Parameters¶
url: string - The URL to requestbody: string? - The body to send.headers: table? - Table containing the headers to send[HeaderKey] = HeaderValue.options: table? - Table containing options.
Returns¶
requestId: integer - ID of the request to await for.
Emits¶
Throws¶
- If request URL is invalid. Check with
checkURLbefore calling this function.
websocketAsync¶
http.websocketAsync( url, headers )
Open a WebSocket connection.
Parameters¶
url: string - The URL to connect to.headers: table? - Table containing the headers to send[HeaderKey] = HeaderValue.
Returns¶
requestId: integer - ID of the request to await for.
Emits¶
Throws¶
- If request URL is invalid. Check with
checkURLbefore calling this function. - If WebSockets are disabled in configuration.
- If maximum concurrent connections is reached.
Related¶
Events¶
request¶
http.request( url, body?, headers?, options? )
Send a HTTP request and wait for response.
Extension
This function is an extension implemented by CapyOS!
Parameters¶
url: string - The URL to requestbody: string? - The body to send.headers: table? - Table containing the headers to send[HeaderKey] = HeaderValue.options: table? - Table containing options.
Returns¶
If successful
response- Response body content
If binary: BinaryReadHandle
If text: ReadHandle
information: HTTPData - Table containing information about the response.
OR¶
If failed
nil: nilmessage: string - Error message.
get¶
http.get( url, headers?, options? )
Send a HTTP GET request and wait for response.
Extension
This function is an extension implemented by CapyOS!
Parameters¶
url: string - The URL to requestheaders: table? - Table containing the headers to send[HeaderKey] = HeaderValue.options: table? - Table containing options.
Returns¶
If successful
response- Response body content
If binary: BinaryReadHandle
If text: ReadHandle
information: HTTPData - Table containing information about the response.
OR¶
If failed
nil: nilmessage: string - Error message.
post¶
http.post( url, body?, headers?, options? )
Send a HTTP GET request and wait for response.
Extension
This function is an extension implemented by CapyOS!
Parameters¶
url: string - The URL to requestbody: string - Body of the requestheaders: table? - Table containing the headers to send[HeaderKey] = HeaderValue.options: table? - Table containing options.
Returns¶
If successful
response- Response body content
If binary: BinaryReadHandle
If text: ReadHandle
information: HTTPData - Table containing information about the response.
OR¶
If failed
nil: nilmessage: string - Error message.
websocket¶
http.websocket( url, headers )
Open a WebSocket connection.
Extension
This function is an extension implemented by CapyOS!
Parameters¶
url: string - The URL to connect to.headers: table? - Table containing the headers to send[HeaderKey] = HeaderValue.
Returns¶
If successful
websocketHandle: WebSocketHandle - WebSocket handle.
OR¶
If failed
nil: nilmessage: string - Error message.
Throws¶
- If request URL is invalid. Check with
checkURLbefore calling this function. - If WebSockets are disabled in configuration.
- If maximum concurrent connections is reached.
Related¶
Events¶
Created: March 11, 2023