UNPKG

4.33 kBTypeScriptView Raw
1export interface AxiosTransformer {
2 (data: any, headers?: any): 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 AxiosRequestConfig {
45 url?: string;
46 method?: Method;
47 baseURL?: string;
48 transformRequest?: AxiosTransformer | AxiosTransformer[];
49 transformResponse?: AxiosTransformer | AxiosTransformer[];
50 headers?: any;
51 params?: any;
52 paramsSerializer?: (params: any) => string;
53 data?: any;
54 timeout?: number;
55 timeoutErrorMessage?: string;
56 withCredentials?: boolean;
57 adapter?: AxiosAdapter;
58 auth?: AxiosBasicCredentials;
59 responseType?: ResponseType;
60 xsrfCookieName?: string;
61 xsrfHeaderName?: string;
62 onUploadProgress?: (progressEvent: any) => void;
63 onDownloadProgress?: (progressEvent: any) => void;
64 maxContentLength?: number;
65 validateStatus?: ((status: number) => boolean) | null;
66 maxBodyLength?: number;
67 maxRedirects?: number;
68 socketPath?: string | null;
69 httpAgent?: any;
70 httpsAgent?: any;
71 proxy?: AxiosProxyConfig | false;
72 cancelToken?: CancelToken;
73 decompress?: boolean;
74}
75
76export interface AxiosResponse<T = any> {
77 data: T;
78 status: number;
79 statusText: string;
80 headers: any;
81 config: AxiosRequestConfig;
82 request?: any;
83}
84
85export interface AxiosError<T = any> extends Error {
86 config: AxiosRequestConfig;
87 code?: string;
88 request?: any;
89 response?: AxiosResponse<T>;
90 isAxiosError: boolean;
91 toJSON: () => object;
92}
93
94export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
95}
96
97export interface CancelStatic {
98 new (message?: string): Cancel;
99}
100
101export interface Cancel {
102 message: string;
103}
104
105export interface Canceler {
106 (message?: string): void;
107}
108
109export interface CancelTokenStatic {
110 new (executor: (cancel: Canceler) => void): CancelToken;
111 source(): CancelTokenSource;
112}
113
114export interface CancelToken {
115 promise: Promise<Cancel>;
116 reason?: Cancel;
117 throwIfRequested(): void;
118}
119
120export interface CancelTokenSource {
121 token: CancelToken;
122 cancel: Canceler;
123}
124
125export interface AxiosInterceptorManager<V> {
126 use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
127 eject(id: number): void;
128}
129
130export interface AxiosInstance {
131 (config: AxiosRequestConfig): AxiosPromise;
132 (url: string, config?: AxiosRequestConfig): AxiosPromise;
133 defaults: AxiosRequestConfig;
134 interceptors: {
135 request: AxiosInterceptorManager<AxiosRequestConfig>;
136 response: AxiosInterceptorManager<AxiosResponse>;
137 };
138 getUri(config?: AxiosRequestConfig): string;
139 request<T = any, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R>;
140 get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
141 delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
142 head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
143 options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
144 post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
145 put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
146 patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
147}
148
149export interface AxiosStatic extends AxiosInstance {
150 create(config?: AxiosRequestConfig): AxiosInstance;
151 Cancel: CancelStatic;
152 CancelToken: CancelTokenStatic;
153 isCancel(value: any): boolean;
154 all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
155 spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
156 isAxiosError(payload: any): payload is AxiosError;
157}
158
159declare const axios: AxiosStatic;
160
161export default axios;