Reqor
A easy way to use the fetch/fetchLater functions.
Static Properties
middlewares: ReqorMiddleware[];
An array of global middlewares applied to all Reqor instances.
Static Methods
static use(middleware: ReqorMiddleware): typeof Reqor;
Use a global middleware that applies to all Reqor instances.
| Param | Type | Description |
|---|---|---|
middleware | ReqorMiddleware | Middleware to add globally. |
Returns: typeof Reqor
static clearMiddlewares(): void;
Clear all global middlewares.
Constructor
constructor(url: string);
Creates a new Reqor instance with the specified base URL.
| Param | Type | Description |
|---|---|---|
url | string | The base URL for requests. |
Properties
This class exposes no public instance properties.
Methods
.after(number: number): this;
After how much time to start performing.
| Param | Type | Description |
|---|---|---|
number | number | Time in milliseconds to delay before performing the request. |
Returns: this
.params(values: { [key: string]: string | number | boolean | null | undefined; } | Array<{ [key: string]: string | number | boolean | null | undefined; }> | URLSearchParams): this;
A function to decide what params to add in the get query.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the params parameter.
| Param | Type | Description |
|---|---|---|
values | { [key: string]: string | number | boolean | null | undefined; } | Array<{ [key: string]: string | number | boolean | null | undefined; }> | URLSearchParams | Query parameters to add. |
Returns: this
.onTimeout(handler: (retryNumber?: number) => any): this;
A function to decide what happens when there is a timeout on a try to connect.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the retry.timeout.onTimeout parameter.
| Param | Type | Description |
|---|---|---|
handler | (retryNumber?: number) => any | Handler function called on timeout, receives the retry number. |
Returns: this
.onTotalTimeout(handler: () => any): this;
A function to decide what happens when there is timeout on the whole try to connect.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the totalTimeout.onTotalTimeout parameter.
| Param | Type | Description |
|---|---|---|
handler | () => any | Handler function called on total timeout. |
Returns: this
.onRetry(handler: (retryNumber?: number) => any): this;
A function to decide what happens when there is a retry attempt.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the retry.onRetry parameter.
| Param | Type | Description |
|---|---|---|
handler | (retryNumber?: number) => any | Handler function called on retry, receives the retry number. |
Returns: this
.retryDelay(number: number, increaseFn?: (current: number) => number): this;
A function to decide how much to delay after a attempt to connect and the function to increase delay.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the retry.delay parameter.
| Param | Type | Description |
|---|---|---|
number | number | Initial delay in milliseconds. |
increaseFn | (current: number) => number | Optional function to increase the delay for subsequent retries. |
Returns: this
.data(data: any): this;
A function to decide what data gets passed to post.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the data parameter.
Important
This is only exclusive for post.
| Param | Type | Description |
|---|---|---|
data | any | Data to be sent in the POST request. |
Returns: this
.headers(headers: Reqor.Headers.Map): this;
A function to decide what headers gets passed to post.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the headers parameter.
Important
This is only exclusive for post.
| Param | Type | Description |
|---|---|---|
headers | Reqor.Headers.Map | Headers to be sent with the request. |
Returns: this
.get(optionsOrMiddleware?: ReqorGetOptions | ReqorLocalMiddlewareInput): Promise<Reqor.Response | Reqor.Response>;
The get property in Reqor allows you to GET a specific url.
| Param | Type | Description |
|---|---|---|
optionsOrMiddleware | ReqorGetOptions|ReqorLocalMiddlewareInput | Options or Middleware Input |
Returns: Promise<Reqor.Response|Reqor.ResponseLater>
.post(data?: any, headersOrOptions?: Reqor.Headers.Map | ReqorPostOptions | ReqorLocalMiddlewareInput, optionsOrMiddleware?: ReqorPostOptions | ReqorLocalMiddlewareInput): Promise<Reqor.Response | Reqor.Response>;
The post property in Reqor allows you to POST to a specific url.
| Param | Type | Description |
|---|---|---|
data | any | undefined | Data to POST to the url. The Content-Type header property will automatically be applied. |
headersOrOptions | Reqor.Headers.Map|ReqorPostOptions|ReqorLocalMiddlewareInput|undefined | Headers, Options, or middleware. |
optionsOrMiddleware | ReqorPostOptions|ReqorLocalMiddlewareInput | Options or middleware |
Returns: Promise<Reqor.Response|Reqor.ResponseLater>
.use(middleware: ReqorMiddleware): this;
Use a local middleware.
| Param | Type | Description |
|---|---|---|
middleware | ReqorMiddleware | Middleware to add. |
Returns: this
.clearMiddlewares(): this;
Clear all middlewares for this reqor instance.
Returns: this
readonly .timeout: (ms: number) => Reqor;
A function to decide after how much time there is a timeout for an attempt.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the timeout.time parameter.
| Param | Type | Description |
|---|---|---|
ms | number | How much Timeout for each retry for the next operation |
Returns: Reqor
readonly .retry: (count: number) => Reqor;
A function to decide how many times to retry the request.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the retry.number parameter.
| Param | Type | Description |
|---|---|---|
count | number | Number of retries for the next operation |
Returns: Reqor
readonly .totalTimeout: (ms: number) => Reqor;
A function to decide the total timeout for the entire request operation.
Important
Calling this function again overrides the current option
Important
This will not be used if you pass the totalTimeout parameter.
| Param | Type | Description |
|---|---|---|
ms | number | Total timeout in milliseconds for the operation |
Returns: Reqor
