Skip to content

Request

Request is a class that represents a single HTTP request. The idea behind this class is to provide some sort of structure and boilerplate for making HTTP requests.

by default, this class will add the following headers:

  • User-Agent: “DiscordLuau”
  • Authorization: “Bot <token>”
  • Content-Type: “application/json”
Request : setBody ( body )  -> ()

Responsible for setting the Body of this request. Body must be a string.

Parameters

body: string
Request : setFlag ( name value )  -> ()

Allows us to define flags for this request, used to flag requests that could potentially contain attachments. and, therefore need to be translated into formdata before we push anything.

Parameters

name: string
value: boolean
Request : addUrlParam ( paramName paramValue )  -> ()

Responsible for adding to the Url Params of this request. Values may be a string or an array of strings; arrays are serialized as repeated query parameters (e.g. key=a&key=b) with full URL encoding applied by the underlying runtime’s net.request implementation.

Parameters

paramName: string
paramValue: string | { string }
Request : addHeader ( headerName headerValue )  -> ()

Responsible for adding to the Headers of this request. Both the header key and values are strings.

You are not allowed to set the following headers:

  • User-Agent
  • Authorization

Parameters

headerName: string
headerValue: string
Request : setUrl ( url )  -> ()

Responsible for setting the URL of this request. URL must be a string, and formatted like so:

Parameters

url: string
Request : setMethod ( method )  -> ()

Responsible for setting the Method of this request. Method must be one of GET, POST, PUT, PATCH, or DELETE.

Methods define the nature of the request, and the response.

Parameters

method: &quot;GET&quot; | &quot;POST&quot; | &quot;PUT&quot; | &quot;PATCH&quot; | &quot;DELETE&quot;
Request : assertToken ( )  -> ()

Responsible for validating the Authorization token of this request. Some calls require token authorization, and some do not, so the relevant calls should assert that the token is set.

Request : addHook ( hookState hookCallback )  -> ()

Enables developers to add a hook to this request. Hooks are functions that are called before or after the request is executed. Hooks are useful for things like logging, or modifying the request before it is executed.

The hook callback should return a boolean, and if it returns false, the request will not be executed.

Parameters

hookState: &quot;BeforeRequest&quot; | &quot;AfterRequest&quot;
hookCallback: FetchResponse?) -> (boolean, any?)
Request : executeAsync ( )  -> ()

Responsible for executing this request asynchronously. This will return a async that will resolve when the request is completed.

This function will decode the response body, and return a table with the following keys:

  • headers: A table of headers returned from the request.
  • body: The body of the request, decoded from the response.
Request . new ( settings )  -> Request

Constructor for the Request object.

Parameters

settings: {
token: string?,
restApiVersion: number,
}

Returns

Request