UNPKG

@rudderstack/integrations-lib

Version:
38 lines 1.92 kB
import { AxiosRequestConfig } from 'axios'; import { ApiResponse, HttpClient, ResponseParser } from './types'; /** * A wrapper around axios to make http requests * * @class AxiosClient * @classdesc * The `AxiosClient` class is a wrapper around the axios library that provides a simplified interface for making HTTP requests. It handles various types of errors and provides a consistent response format. * * @param {AxiosRequestConfig} options - The default options for the http client * * @example * const axiosClient = new AxiosClient({ timeout: 1000 * 10 }); * const response = await axiosClient.post("https://example.com", { foo: "bar" }); * if (response.type === "success") { * console.log(response.statusCode); * console.log(response.responseBody); * } else if (response.type === "application-error") { * console.log(response.statusCode); * console.log(response.message); * console.log(response.responseBody); * } else if (response.type === "client-error") { * console.log(response.statusCode); * console.log(response.message); * } */ export declare class AxiosClient implements HttpClient { private options; private instance; constructor(options?: AxiosRequestConfig); private makeRequest; get<T>(url: string, options?: AxiosRequestConfig, responseParser?: ResponseParser<T>): Promise<ApiResponse<T>>; post<T>(url: string, data?: any, options?: AxiosRequestConfig, responseParser?: ResponseParser<T>): Promise<ApiResponse<T>>; put<T>(url: string, data?: any, options?: AxiosRequestConfig, responseParser?: ResponseParser<T>): Promise<ApiResponse<T>>; patch<T>(url: string, data?: any, options?: AxiosRequestConfig, responseParser?: ResponseParser<T>): Promise<ApiResponse<T>>; delete<T>(url: string, options?: AxiosRequestConfig, responseParser?: ResponseParser<T>): Promise<ApiResponse<T>>; } //# sourceMappingURL=axios_client.d.ts.map