@marxlnfcs/wildduck-api
Version:
Provides a client to interact with the wildduck api
48 lines (47 loc) • 2.44 kB
TypeScript
/// <reference types="node" />
import { AxiosError, AxiosProxyConfig, AxiosRequestConfig, AxiosResponse, Method, responseEncoding, ResponseType } from "axios";
import { IWildduckClientOptions } from "../interfaces/client-options.interface";
import { WildduckException } from "../exceptions/http.exception";
export declare function createHttpClient(options: IWildduckClientOptions): HttpClient;
export interface HttpOptions<Body = any> {
headers?: {
[name: string]: string | number | null | undefined;
} | null;
params?: {
[key: string]: string | number | boolean | null | undefined;
} | null;
query?: {
[key: string]: string | number | boolean | null | undefined | Date | Array<string | number | boolean | null | undefined | Date>;
} | null;
body?: Body | FormData | null;
responseType?: ResponseType;
responseEncoding?: responseEncoding | string;
}
export interface HttpRequestConfig extends AxiosRequestConfig {
url_full: string;
}
export type HttpResult<Result = any> = Promise<AxiosResponse<Result>>;
export declare class HttpClient {
private options;
private http;
constructor(options: IWildduckClientOptions);
createUrl(path?: string, options?: Pick<HttpOptions, 'params' | 'query'>): string;
get<Response = any>(path?: string | string[], options?: Omit<HttpOptions, 'body'>): HttpResult<Response>;
post<Response = any>(path?: string | string[], options?: HttpOptions): HttpResult<Response>;
put<Response = any>(path?: string | string[], options?: HttpOptions): HttpResult<Response>;
patch<Response = any>(path?: string | string[], options?: HttpOptions): HttpResult<Response>;
delete<Response = any>(path?: string | string[], options?: HttpOptions): HttpResult<Response>;
download(path?: string | string[], options?: {
method?: Method;
} & HttpOptions): HttpResult<Buffer>;
upload<Response = any>(path?: string | string[], options?: {
method?: Method;
} & HttpOptions): HttpResult<Response>;
request<Response = any>(method: Method, path?: string | string[], options?: HttpOptions): HttpResult<Response>;
private onRequest;
private onResponse;
private onError;
private buildRequestOptions;
}
export declare function createHttpProxySettings(options: IWildduckClientOptions): AxiosProxyConfig | false;
export declare function createHttpException(e: AxiosError): WildduckException;