Skip to main content
Module

x/dynablox_opencloud/src/rest/RESTController.ts>RESTController

A Roblox OpenCloud API wrapper for Deno and NodeJS written in TypeScript.
Latest
class RESTController
import { RESTController } from "https://deno.land/x/dynablox_opencloud@v0.2.2/src/rest/RESTController.ts";

Constructors

new
RESTController(options: RESTControllerOptions)

Construct a new RESTController.

Properties

private
readonly
_credentials: ClientAuthenticationInit

Client credentials.

readonly
aliases: Record<string, string>

String-string aliases for URLs, Whenever an a lias is found in a URL, it will attempt to format it.

E.g.: RBXURL key with value {0}.roblox.com. When we format it with this.formatUrl(), if the URL is: {RBXURL:auth}/v1/logout, we replace {0} with "auth".

readonly
authenticationType

The authentication type of the client.

If it is "APIKey" then it will authenticate through the OpenCloud endpoints.

If it is "Bearer" then it will authenticate through the OAuth endpoints.

If it is "OAuthApplication" then it will authenticate through the OAuth application endpoints.

readonly
credentials
optional
defaultHeaders: Record<string, string> | Headers

The default headers to add to requests, values may be modified later on.

readonly
optional
fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>

Custom fetch implementation to use instead of the default fetch.

Methods

protected
_httpRequest<Expect = unknown>(request: InternalHTTPRequest): Promise<HTTPResponse<Expect>>
formatBody(body: HTTPRequestBodyContent): { body:
| string
| Uint8Array
; type?: string; }

Format a body to be used in requests. This will also return a contentType to be sent in the headers.

formatUrl(
url: string,
query?: URLSearchParams | Record<string, unknown>,
protocol?,
): URL

Formats a URL given a URL string, query, protocol, and aliases. Aliases will be found and formatted with the parameters with this.formatWithAliases(target)

formatWithAliases(target: string): string

Format a string with aliases given a target. Unknown alias calles are replaced with null.

E.g.: RBXURL key with value {0}.roblox.com. When we format it if the URL is: {RBXURL:auth}/v1/logout, we replace {0} with "auth" from alias and replace the alias call.

handleRequestHeaders(
_url: URL,
contentType?: string,
): Headers

Checks if the RESTController has authentication values set.

httpRequest<Expect = unknown>(request: HTTPRequest): Promise<HTTPResponse<Expect>>

Public-facing request function. This is different from the protected _httpRequest function in a way that error handling can be done.

setCredentialsValue(credentials: ClientAuthenticationInit["value"]): void

Set the current credentials value. Note: When we migrate all authentication fields to credentials, this will be much more type-safe.