Skip to main content

Class: HTTPRequest

Class for handling HTTP requests with customizable headers, body, and parameters.

Constructors

constructor

new HTTPRequest(cookie?)

Parameters

NameType
cookie?string

Defined in

src/request/request.ts:76

Properties

body

Private body: HTTPBody = {}

Body of the request.

Defined in

src/request/request.ts:32


cache

Private cache: Cache

The cache used for the request

Defined in

src/request/request.ts:37


ds

Private ds: boolean = false

Flag indicating whether Dynamic Security is used.

Defined in

src/request/request.ts:63


headers

Private headers: HTTPHeaders

Defined in

src/request/request.ts:42


http

Optional http: Object

Type declaration

NameType
code?number
request?object
response?object

Defined in

src/request/request.ts:70


params

Private params: HTTPQueryParams = {}

Query parameters for the request.

Defined in

src/request/request.ts:27


retries

Private retries: number = 1

The number of request attempts made.

Defined in

src/request/request.ts:68

Methods

send

send(url, method?, ttl?): Promise<HTTPServerResponse>

Send the HTTP request.

Throws

if an error occurs rejects with a HoyoAPIError

Parameters

NameTypeDefault valueDescription
urlstringundefinedThe URL to send the request to.
method"GET" | "POST"'GET'The HTTP method to use. Defaults to 'GET'.
ttlnumber60The TTL value for the cached data in seconds.

Returns

Promise<HTTPServerResponse>

A Promise that resolves with the response data, or rejects with a HoyoAPIError if an error occurs.

Defined in

src/request/request.ts:147


setBody

setBody(data): HTTPRequest

Set Body Parameter

Parameters

NameType
dataHTTPBody

Returns

HTTPRequest

This instance of Request object.

Defined in

src/request/request.ts:98


setDs

setDs(flag?): HTTPRequest

Set to used Dynamic Security or not

Parameters

NameTypeDefault valueDescription
flagbooleantrueboolean Flag indicating whether to use dynamic security or not (default: true).

Returns

HTTPRequest

The current Request instance.

Defined in

src/request/request.ts:133


setLang

setLang(lang): HTTPRequest

Set Language

Parameters

NameTypeDescription
langstringLanguage Language that used for return of API (default: Language.ENGLISH).

Returns

HTTPRequest

Defined in

src/request/request.ts:121


setQueryParams

setQueryParams(params): HTTPRequest

Sets search parameters or query parameter.

Parameters

NameTypeDescription
paramsHTTPQueryParamsAn object of query parameter to be set.

Returns

HTTPRequest

Returns this Request object.

Defined in

src/request/request.ts:87


setReferer

setReferer(url): HTTPRequest

Set Referer Headers

Parameters

NameTypeDescription
urlstring | URLThe URL string of referer

Returns

HTTPRequest

The updated Request instance.

Defined in

src/request/request.ts:109