Skip to content

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.

ParamTypeDescription
middlewareReqorMiddlewareMiddleware 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.

ParamTypeDescription
urlstringThe base URL for requests.

Properties

This class exposes no public instance properties.

Methods

.after(number: number): this;

After how much time to start performing.

ParamTypeDescription
numbernumberTime 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.

ParamTypeDescription
values{ [key: string]: string | number | boolean | null | undefined; } | Array<{ [key: string]: string | number | boolean | null | undefined; }> | URLSearchParamsQuery 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.

ParamTypeDescription
handler(retryNumber?: number) => anyHandler 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.

ParamTypeDescription
handler() => anyHandler 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.

ParamTypeDescription
handler(retryNumber?: number) => anyHandler 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.

ParamTypeDescription
numbernumberInitial delay in milliseconds.
increaseFn(current: number) => numberOptional 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.

ParamTypeDescription
dataanyData 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.

ParamTypeDescription
headersReqor.Headers.MapHeaders 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.

ParamTypeDescription
optionsOrMiddlewareReqorGetOptions|ReqorLocalMiddlewareInputOptions 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.

ParamTypeDescription
dataany | undefinedData to POST to the url. The Content-Type header property will automatically be applied.
headersOrOptionsReqor.Headers.Map|ReqorPostOptions|ReqorLocalMiddlewareInput|undefinedHeaders, Options, or middleware.
optionsOrMiddlewareReqorPostOptions|ReqorLocalMiddlewareInputOptions or middleware

Returns: Promise<Reqor.Response|Reqor.ResponseLater>

.use(middleware: ReqorMiddleware): this;

Use a local middleware.

ParamTypeDescription
middlewareReqorMiddlewareMiddleware 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.

ParamTypeDescription
msnumberHow 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.

ParamTypeDescription
countnumberNumber 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.

ParamTypeDescription
msnumberTotal timeout in milliseconds for the operation

Returns: Reqor