index.d.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. export interface AxiosTransformer {
  2. (data: any, headers?: any): any;
  3. }
  4. export interface AxiosAdapter {
  5. (config: AxiosRequestConfig): AxiosPromise<any>;
  6. }
  7. export interface AxiosBasicCredentials {
  8. username: string;
  9. password: string;
  10. }
  11. export interface AxiosProxyConfig {
  12. host: string;
  13. port: number;
  14. auth?: {
  15. username: string;
  16. password:string;
  17. }
  18. }
  19. export interface AxiosRequestConfig {
  20. url?: string;
  21. method?: string;
  22. baseURL?: string;
  23. transformRequest?: AxiosTransformer | AxiosTransformer[];
  24. transformResponse?: AxiosTransformer | AxiosTransformer[];
  25. headers?: any;
  26. params?: any;
  27. paramsSerializer?: (params: any) => string;
  28. data?: any;
  29. timeout?: number;
  30. withCredentials?: boolean;
  31. adapter?: AxiosAdapter;
  32. auth?: AxiosBasicCredentials;
  33. responseType?: string;
  34. xsrfCookieName?: string;
  35. xsrfHeaderName?: string;
  36. onUploadProgress?: (progressEvent: any) => void;
  37. onDownloadProgress?: (progressEvent: any) => void;
  38. maxContentLength?: number;
  39. validateStatus?: (status: number) => boolean;
  40. maxRedirects?: number;
  41. httpAgent?: any;
  42. httpsAgent?: any;
  43. proxy?: AxiosProxyConfig | false;
  44. cancelToken?: CancelToken;
  45. }
  46. export interface AxiosResponse<T = any> {
  47. data: T;
  48. status: number;
  49. statusText: string;
  50. headers: any;
  51. config: AxiosRequestConfig;
  52. request?: any;
  53. }
  54. export interface AxiosError extends Error {
  55. config: AxiosRequestConfig;
  56. code?: string;
  57. request?: any;
  58. response?: AxiosResponse;
  59. }
  60. export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
  61. }
  62. export interface CancelStatic {
  63. new (message?: string): Cancel;
  64. }
  65. export interface Cancel {
  66. message: string;
  67. }
  68. export interface Canceler {
  69. (message?: string): void;
  70. }
  71. export interface CancelTokenStatic {
  72. new (executor: (cancel: Canceler) => void): CancelToken;
  73. source(): CancelTokenSource;
  74. }
  75. export interface CancelToken {
  76. promise: Promise<Cancel>;
  77. reason?: Cancel;
  78. throwIfRequested(): void;
  79. }
  80. export interface CancelTokenSource {
  81. token: CancelToken;
  82. cancel: Canceler;
  83. }
  84. export interface AxiosInterceptorManager<V> {
  85. use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
  86. eject(id: number): void;
  87. }
  88. export interface AxiosInstance {
  89. (config: AxiosRequestConfig): AxiosPromise;
  90. (url: string, config?: AxiosRequestConfig): AxiosPromise;
  91. defaults: AxiosRequestConfig;
  92. interceptors: {
  93. request: AxiosInterceptorManager<AxiosRequestConfig>;
  94. response: AxiosInterceptorManager<AxiosResponse>;
  95. };
  96. request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
  97. get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
  98. delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
  99. head(url: string, config?: AxiosRequestConfig): AxiosPromise;
  100. post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
  101. put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
  102. patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
  103. }
  104. export interface AxiosStatic extends AxiosInstance {
  105. create(config?: AxiosRequestConfig): AxiosInstance;
  106. Cancel: CancelStatic;
  107. CancelToken: CancelTokenStatic;
  108. isCancel(value: any): boolean;
  109. all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
  110. spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
  111. }
  112. declare const Axios: AxiosStatic;
  113. export default Axios;