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:77

Properties

body

Private body: HTTPBody = {}

Body of the request.

Defined in

src/request/request.ts:33


cache

Private cache: Cache

The cache used for the request

Defined in

src/request/request.ts:38


ds

Private ds: boolean = false

Flag indicating whether Dynamic Security is used.

Defined in

src/request/request.ts:64


headers

Private headers: HTTPHeaders

Defined in

src/request/request.ts:43


http

Optional http: Object

Type declaration

NameType
code?number
request?object
response?object

Defined in

src/request/request.ts:71


params

Private params: HTTPQueryParams = {}

Query parameters for the request.

Defined in

src/request/request.ts:28


retries

Private retries: number = 1

The number of request attempts made.

Defined in

src/request/request.ts:69

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:153


setBody

setBody(data): HTTPRequest

Set Body Parameter

Parameters

NameType
dataHTTPBody

Returns

HTTPRequest

This instance of Request object.

Defined in

src/request/request.ts:99


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:139


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:122


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:88


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:110


setRequestHeaders

setRequestHeaders(key, value): HTTPRequest

Parameters

NameType
keystring
valuestring

Returns

HTTPRequest

Defined in

src/request/request.ts:128