# Class: Request

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

# Table of contents

# Constructors

# Properties

# Methods

# Constructors

# constructor

new Request(cookies?)

Constructor for the Request class.

# Parameters

Name Type Default value Description
cookies null | string null A string of cookies to be added to the request headers (default: null).

# Defined in

src/request/request.ts:56 (opens new window)

# Properties

# body

Private body: BaseType

Body of the request.

# Defined in

src/request/request.ts:29 (opens new window)


# cache

Private cache: Cache

The cache used for the request

# Defined in

src/request/request.ts:39 (opens new window)


# ds

Private ds: boolean

Flag indicating whether Dynamic Security is used.

# Defined in

src/request/request.ts:44 (opens new window)


# headers

Private headers: BaseType

# Defined in

src/request/request.ts:24 (opens new window)


# params

Private params: BaseType

Query parameters for the request.

# Defined in

src/request/request.ts:34 (opens new window)


# retries

Private retries: number = 1

The number of request attempts made.

# Defined in

src/request/request.ts:49 (opens new window)

# Methods

# send

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

Send the HTTP request.

Throws

if an error occurs rejects with a HoyolabError

# Parameters

Name Type Default value Description
url string undefined The URL to send the request to.
method "GET" | "POST" 'GET' The HTTP method to use. Defaults to 'GET'.
ttl? number undefined The TTL value for the cached data in seconds.

# Returns

Promise<IResponse>

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

# Defined in

src/request/request.ts:142 (opens new window)


# setBody

setBody(body): Request

Set Body Parameter

# Parameters

Name Type Description
body BaseType RequestBodyType as object containing the body parameters.

# Returns

Request

This instance of Request object.

# Defined in

src/request/request.ts:92 (opens new window)


# setDs

setDs(flag?): Request

Set to used Dynamic Security or not

# Parameters

Name Type Default value Description
flag boolean true boolean Flag indicating whether to use dynamic security or not (default: true).

# Returns

Request

The current Request instance.

# Defined in

src/request/request.ts:116 (opens new window)


# setLang

setLang(lang?): Request

Set Language

# Parameters

Name Type Default value Description
lang LanguageEnum LanguageEnum.ENGLISH Language Language that used for return of API (default: Language.ENGLISH).

# Returns

Request

# Defined in

src/request/request.ts:127 (opens new window)


# setParams

setParams(params): Request

Sets search parameters or query parameter.

# Parameters

Name Type Description
params BaseType An object of query parameter to be set.

# Returns

Request

  • Returns this Request object.

# Defined in

src/request/request.ts:104 (opens new window)


# setReferer

setReferer(url): Request

Set Referer Headers

# Parameters

Name Type Description
url string The URL string of referer

# Returns

Request

The updated Request instance.

# Defined in

src/request/request.ts:79 (opens new window)