Skip to main content

Request()

A module for performing network request to the internet that was introduced on version 1.0.0.31

Constructor

Request(url: string)

Parameters

ParametersTypeDescription
urlstringThe site url can be https or http

Methods

setHeader(key: string, value: string): Request

Set a custom header for the HTTP request.

Parameters

ParametersTypeDescription
keystringThe header name
valuestringThe header value

Returns

Request - Returns the Request object for method chaining

setParameter(key: string, value: string): Request

Set a parameter for the request body (used with POST/PUT requests).

Parameters

ParametersTypeDescription
keystringThe parameter name
valuestringThe parameter value

Returns

Request - Returns the Request object for method chaining

get(): Response

Execute a GET request and return a Response object.

Returns

Response - The response object containing the server response

post(): Response

Execute a POST request and return a Response object.

Returns

Response - The response object containing the server response

put(): Response

Execute a PUT request and return a Response object.

Returns

Response - The response object containing the server response

delete(): Response

Execute a DELETE request and return a Response object.

Returns

Response - The response object containing the server response

Examples

Basic GET Request

local response = Request("https://api.example.com/data"):get()
local data = response:getData()
local statusCode = response:getResponseCode()

POST Request with Headers and Parameters

local response = Request("https://api.example.com/users")
:setHeader("Content-Type", "application/json")
:setHeader("Authorization", "Bearer token123")
:setParameter("name", "John Doe")
:setParameter("email", "john@example.com")
:post()

Chaining Multiple Methods

-- Request objects support method chaining for fluent API
local response = Request("https://api.example.com/data")
:setHeader("API-Key", "your-api-key")
:setParameter("query", "search term")
:setParameter("limit", "10")
:get()