Class: HTTPRequest
Class for handling HTTP requests with customizable headers, body, and parameters.
Constructors
constructor
• new HTTPRequest(cookie?
)
Parameters
Name | Type |
---|---|
cookie? | string |
Defined in
Properties
body
• Private
body: HTTPBody
= {}
Body of the request.
Defined in
cache
• Private
cache: Cache
The cache used for the request
Defined in
ds
• Private
ds: boolean
= false
Flag indicating whether Dynamic Security is used.
Defined in
headers
• Private
headers: HTTPHeaders
Defined in
http
• Optional
http: Object
Type declaration
Name | Type |
---|---|
code? | number |
request? | object |
response? | object |
Defined in
params
• Private
params: HTTPQueryParams
= {}
Query parameters for the request.
Defined in
retries
• Private
retries: number
= 1
The number of request attempts made.
Defined in
Methods
send
▸ send(url
, method?
, ttl?
): Promise
<HTTPServerResponse
>
Send the HTTP request.
Throws
if an error occurs rejects with a HoyoAPIError
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 | 60 | The 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
setBody
▸ setBody(data
): HTTPRequest
Set Body Parameter
Parameters
Name | Type |
---|---|
data | HTTPBody |
Returns
This instance of Request object.
Defined in
setDs
▸ setDs(flag?
): HTTPRequest
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
The current Request instance.
Defined in
setLang
▸ setLang(lang
): HTTPRequest
Set Language
Parameters
Name | Type | Description |
---|---|---|
lang | string | Language Language that used for return of API (default: Language.ENGLISH). |
Returns
Defined in
setQueryParams
▸ setQueryParams(params
): HTTPRequest
Sets search parameters or query parameter.
Parameters
Name | Type | Description |
---|---|---|
params | HTTPQueryParams | An object of query parameter to be set. |
Returns
Returns this Request object.
Defined in
setReferer
▸ setReferer(url
): HTTPRequest
Set Referer Headers
Parameters
Name | Type | Description |
---|---|---|
url | string | URL | The URL string of referer |
Returns
The updated Request instance.
Defined in
setRequestHeaders
▸ setRequestHeaders(key
, value
): HTTPRequest
Parameters
Name | Type |
---|---|
key | string |
value | string |