UNPKG

4.78 kBTypeScriptView Raw
1export interface AxiosTransformer {
2 (data: any, headers?: Record<string, string>): any;
3}
4
5export interface AxiosAdapter {
6 (config: AxiosRequestConfig): AxiosPromise<any>;
7}
8
9export interface AxiosBasicCredentials {
10 username: string;
11 password: string;
12}
13
14export interface AxiosProxyConfig {
15 host: string;
16 port: number;
17 auth?: {
18 username: string;
19 password:string;
20 };
21 protocol?: string;
22}
23
24export type Method =
25 | 'get' | 'GET'
26 | 'delete' | 'DELETE'
27 | 'head' | 'HEAD'
28 | 'options' | 'OPTIONS'
29 | 'post' | 'POST'
30 | 'put' | 'PUT'
31 | 'patch' | 'PATCH'
32 | 'purge' | 'PURGE'
33 | 'link' | 'LINK'
34 | 'unlink' | 'UNLINK'
35
36export type ResponseType =
37 | 'arraybuffer'
38 | 'blob'
39 | 'document'
40 | 'json'
41 | 'text'
42 | 'stream'
43
44export interface TransitionalOptions{
45 silentJSONParsing: boolean;
46 forcedJSONParsing: boolean;
47 clarifyTimeoutError: boolean;
48}
49
50export interface AxiosRequestConfig<T = any> {
51 url?: string;
52 method?: Method;
53 baseURL?: string;
54 transformRequest?: AxiosTransformer | AxiosTransformer[];
55 transformResponse?: AxiosTransformer | AxiosTransformer[];
56 headers?: Record<string, string>;
57 params?: any;
58 paramsSerializer?: (params: any) => string;
59 data?: T;
60 timeout?: number;
61 timeoutErrorMessage?: string;
62 withCredentials?: boolean;
63 adapter?: AxiosAdapter;
64 auth?: AxiosBasicCredentials;
65 responseType?: ResponseType;
66 xsrfCookieName?: string;
67 xsrfHeaderName?: string;
68 onUploadProgress?: (progressEvent: any) => void;
69 onDownloadProgress?: (progressEvent: any) => void;
70 maxContentLength?: number;
71 validateStatus?: ((status: number) => boolean) | null;
72 maxBodyLength?: number;
73 maxRedirects?: number;
74 socketPath?: string | null;
75 httpAgent?: any;
76 httpsAgent?: any;
77 proxy?: AxiosProxyConfig | false;
78 cancelToken?: CancelToken;
79 decompress?: boolean;
80 transitional?: TransitionalOptions
81 signal?: AbortSignal;
82}
83
84export interface AxiosResponse<T = never> {
85 data: T;
86 status: number;
87 statusText: string;
88 headers: Record<string, string>;
89 config: AxiosRequestConfig<T>;
90 request?: any;
91}
92
93export interface AxiosError<T = never> extends Error {
94 config: AxiosRequestConfig;
95 code?: string;
96 request?: any;
97 response?: AxiosResponse<T>;
98 isAxiosError: boolean;
99 toJSON: () => object;
100}
101
102export interface AxiosPromise<T = never> extends Promise<AxiosResponse<T>> {
103}
104
105export interface CancelStatic {
106 new (message?: string): Cancel;
107}
108
109export interface Cancel {
110 message: string;
111}
112
113export interface Canceler {
114 (message?: string): void;
115}
116
117export interface CancelTokenStatic {
118 new (executor: (cancel: Canceler) => void): CancelToken;
119 source(): CancelTokenSource;
120}
121
122export interface CancelToken {
123 promise: Promise<Cancel>;
124 reason?: Cancel;
125 throwIfRequested(): void;
126}
127
128export interface CancelTokenSource {
129 token: CancelToken;
130 cancel: Canceler;
131}
132
133export interface AxiosInterceptorManager<V> {
134 use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any): number;
135 eject(id: number): void;
136}
137
138export class Axios {
139 constructor(config?: AxiosRequestConfig);
140 defaults: AxiosRequestConfig;
141 interceptors: {
142 request: AxiosInterceptorManager<AxiosRequestConfig>;
143 response: AxiosInterceptorManager<AxiosResponse>;
144 };
145 getUri(config?: AxiosRequestConfig): string;
146 request<T = never, R = AxiosResponse<T>> (config: AxiosRequestConfig<T>): Promise<R>;
147 get<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
148 delete<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
149 head<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
150 options<T = never, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig<T>): Promise<R>;
151 post<T = never, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
152 put<T = never, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
153 patch<T = never, R = AxiosResponse<T>>(url: string, data?: T, config?: AxiosRequestConfig<T>): Promise<R>;
154}
155
156export interface AxiosInstance extends Axios {
157 (config: AxiosRequestConfig): AxiosPromise;
158 (url: string, config?: AxiosRequestConfig): AxiosPromise;
159}
160
161export interface AxiosStatic extends AxiosInstance {
162 create(config?: AxiosRequestConfig): AxiosInstance;
163 Cancel: CancelStatic;
164 CancelToken: CancelTokenStatic;
165 Axios: typeof Axios;
166 readonly VERSION: string;
167 isCancel(value: any): boolean;
168 all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
169 spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
170 isAxiosError(payload: any): payload is AxiosError;
171}
172
173declare const axios: AxiosStatic;
174
175export default axios;