dash-core
Version:
A foundational toolkit of types, collections, services, and architectural patterns designed to accelerate application development.
34 lines (33 loc) • 2 kB
TypeScript
import { AxiosRequestConfig, AxiosResponse } from 'axios';
import { ExponentialBackoffOptions } from 'dash-core';
/**
* Provides HTTP GET and POST requests with retries using exponential backoff.
*/
export declare class RestRequest {
private readonly throwException;
private backoff;
/**
* Creates an instance of the RestRequest class.
* @param {boolean} [throwException=false] - Whether to throw the error after retries fail. If false, the promise will reject.
* @param {ExponentialBackoffOptions} [backoffOption] - The configuration for the exponential backoff algorithm.
* If not provided, defaults will be used (initial delay: 5 seconds, max delay: 30 seconds, factor: 2).
*/
constructor(throwException?: boolean, backoffOption?: ExponentialBackoffOptions);
/**
* Makes an HTTP GET request to the specified URL with the optional configuration and retries on failure.
* The request is retried using exponential backoff.
* @param {string} url - The URL to send the GET request to.
* @param {AxiosRequestConfig} [config] - The optional configuration for the GET request.
* @returns {Promise<AxiosResponse<T>>} A promise that resolves with the response of the GET request.
*/
get<T = any>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
/**
* Makes an HTTP POST request to the specified URL with the provided data and optional configuration and retries on failure.
* The request is retried using exponential backoff.
* @param {string} url - The URL to send the POST request to.
* @param {any} [data] - The optional data to send in the body of the POST request.
* @param {AxiosRequestConfig} [config] - The optional configuration for the POST request.
* @returns {Promise<AxiosResponse<T>>} A promise that resolves with the response of the POST request.
*/
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
}