// Type definitions for axios 0.9.1 // Project: https://github.com/mzabriskie/axios // Definitions by: Marcel Buesing // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace Axios { interface IThenable { then(onFulfilled?: (value: R) => U | IThenable, onRejected?: (error: any) => U | IThenable): IThenable; then(onFulfilled?: (value: R) => U | IThenable, onRejected?: (error: any) => void): IThenable; } interface IPromise extends IThenable { then(onFulfilled?: (value: R) => U | IThenable, onRejected?: (error: any) => U | IThenable): IPromise; then(onFulfilled?: (value: R) => U | IThenable, onRejected?: (error: any) => void): IPromise; catch(onRejected?: (error: any) => U | IThenable): IPromise; } /** * HTTP Basic auth details */ interface AxiosHttpBasicAuth { username: string; password: string; } /** * Common axios XHR config interface * - request body data type */ interface AxiosXHRConfigBase { /** * will be prepended to `url` unless `url` is absolute. * It can be convenient to set `baseURL` for an instance * of axios to pass relative URLs to methods of that instance. */ baseURL?: string; /** * custom headers to be sent */ headers?: {[key: string]: any}; /** * URL parameters to be sent with the request */ params?: Object; /** * optional function in charge of serializing `params` * (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/) */ paramsSerializer?: (params: Object) => string; /** * specifies the number of milliseconds before the request times out. * If the request takes longer than `timeout`, the request will be aborted. */ timeout?: number; /** * indicates whether or not cross-site Access-Control requests * should be made using credentials */ withCredentials?: boolean; /** * indicates that HTTP Basic auth should be used, and supplies * credentials. This will set an `Authorization` header, * overwriting any existing `Authorization` custom headers you have * set using `headers`. */ auth?: AxiosHttpBasicAuth; /** * indicates the type of data that the server will respond with * options are 'arraybuffer', 'blob', 'document', 'json', 'text' */ responseType?: string; /** * name of the cookie to use as a value for xsrf token */ xsrfCookieName?: string; /** * name of the http header that carries the xsrf token value */ xsrfHeaderName?: string; /** * Change the request data before it is sent to the server. * This is only applicable for request methods 'PUT', 'POST', and 'PATCH' * The last function in the array must return a string or an ArrayBuffer */ transformRequest?: ((data: T) => U) | [(data: T) => U]; /** * change the response data to be made before it is passed to then/catch */ transformResponse?: (data: T) => U; } /** * - request body data type */ interface AxiosXHRConfig extends AxiosXHRConfigBase { /** * server URL that will be used for the request, options are: * GET, PUT, POST, DELETE, CONNECT, HEAD, OPTIONS, TRACE, PATCH */ url: string; /** * request method to be used when making the request */ method?: string; /** * data to be sent as the request body * Only applicable for request methods 'PUT', 'POST', and 'PATCH' * When no `transformRequest` is set, must be a string, an ArrayBuffer or a hash */ data?: T; } interface AxiosXHRConfigDefaults extends AxiosXHRConfigBase { /** * custom headers to be sent */ headers: { common: {[index: string]: string}; patch: {[index: string]: string}; post: {[index: string]: string}; put: {[index: string]: string}; }; } /** * - expected response type, * - request body data type */ interface AxiosXHR { /** * Response that was provided by the server */ data: T; /** * HTTP status code from the server response */ status: number; /** * HTTP status message from the server response */ statusText: string; /** * headers that the server responded with */ headers: Object; /** * config that was provided to `axios` for the request */ config: AxiosXHRConfig; } interface Interceptor { /** * intercept request before it is sent */ request: RequestInterceptor; /** * intercept response of request when it is received. */ response: ResponseInterceptor } type InterceptorId = number; interface RequestInterceptor { /** * - request body data type */ use(fulfilledFn: (config: AxiosXHRConfig) => AxiosXHRConfig): InterceptorId; use(fulfilledFn: (config: AxiosXHRConfig) => AxiosXHRConfig, rejectedFn: (error: any) => any) : InterceptorId; eject(interceptorId: InterceptorId): void; } interface ResponseInterceptor { /** * - expected response type */ use(fulfilledFn: (config: Axios.AxiosXHR) => Axios.AxiosXHR): InterceptorId; use(fulfilledFn: (config: Axios.AxiosXHR) => Axios.AxiosXHR, rejectedFn: (error: any) => any) : InterceptorId; eject(interceptorId: InterceptorId): void; } /** * - expected response type, * - request body data type */ interface AxiosInstance { /** * Send request as configured */ (config: AxiosXHRConfig): IPromise>; /** * Send request as configured */ new (config: AxiosXHRConfig): IPromise>; /** * Send request as configured */ request(config: AxiosXHRConfig): IPromise>; /** * intercept requests or responses before they are handled by then or catch */ interceptors: Interceptor; /** * Config defaults */ defaults: AxiosXHRConfigDefaults; /** * equivalent to `Promise.all` */ all(values: [T1 | IPromise>, T2 | IPromise>, T3 | IPromise>, T4 | IPromise>, T5 | IPromise>, T6 | IPromise>, T7 | IPromise>, T8 | IPromise>, T9 | IPromise>, T10 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IPromise>, T2 | IPromise>, T3 | IPromise>, T4 | IPromise>, T5 | IPromise>, T6 | IPromise>, T7 | IPromise>, T8 | IPromise>, T9 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IPromise>, T2 | IPromise>, T3 | IPromise>, T4 | IPromise>, T5 | IPromise>, T6 | IPromise>, T7 | IPromise>, T8 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IPromise>, T2 | IPromise>, T3 | IPromise>, T4 | IPromise>, T5 | IPromise>, T6 | IPromise>, T7 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IPromise>, T2 | IPromise>, T3 | IPromise>, T4 | IPromise>, T5 | IPromise>, T6 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IPromise>, T2 | IPromise>, T3 | IPromise>, T4 | IPromise>, T5 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IPromise>, T2 | IPromise>, T3 | IPromise>, T4 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IPromise>, T2 | IPromise>, T3 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR, AxiosXHR]>; all(values: [T1 | IPromise>, T2 | IPromise>]): IPromise<[AxiosXHR, AxiosXHR]>; /** * spread array parameter to `fn`. * note: alternative to `spread`, destructuring assignment. */ spread(fn: (t1: T1, t2: T2) => U): (arr: ([T1, T2])) => U; /** * convenience alias, method = GET */ get(url: string, config?: AxiosXHRConfigBase): IPromise>; /** * convenience alias, method = DELETE */ delete(url: string, config?: AxiosXHRConfigBase): IPromise>; /** * convenience alias, method = HEAD */ head(url: string, config?: AxiosXHRConfigBase): IPromise>; /** * convenience alias, method = POST */ post(url: string, data?: any, config?: AxiosXHRConfigBase): IPromise>; /** * convenience alias, method = PUT */ put(url: string, data?: any, config?: AxiosXHRConfigBase): IPromise>; /** * convenience alias, method = PATCH */ patch(url: string, data?: any, config?: AxiosXHRConfigBase): IPromise>; } /** * - expected response type, */ interface AxiosStatic extends AxiosInstance { /** * create a new instance of axios with a custom config */ create(config: AxiosXHRConfigBase): AxiosInstance; } } declare var axios: Axios.AxiosStatic; declare module "axios" { export = axios; }