axios 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.11.1 (May 17, 2016)
4
+
5
+ - Fixing IE CORS support ([#313](https://github.com/mzabriskie/axios/pull/313))
6
+ - Fixing detection of `FormData` ([#325](https://github.com/mzabriskie/axios/pull/325))
7
+ - Adding `Axios` class to exports ([#321](https://github.com/mzabriskie/axios/pull/321))
8
+
3
9
  ### 0.11.0 (Apr 26, 2016)
4
10
 
5
11
  - Adding support for Stream with HTTP adapter ([#296](https://github.com/mzabriskie/axios/pull/296))
package/README.md ADDED
@@ -0,0 +1,463 @@
1
+ # axios
2
+
3
+ [![npm version](https://img.shields.io/npm/v/axios.svg?style=flat-square)](https://www.npmjs.org/package/axios)
4
+ [![build status](https://img.shields.io/travis/mzabriskie/axios.svg?style=flat-square)](https://travis-ci.org/mzabriskie/axios)
5
+ [![code coverage](https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square)](https://coveralls.io/r/mzabriskie/axios)
6
+ [![npm downloads](https://img.shields.io/npm/dm/axios.svg?style=flat-square)](https://www.npmjs.org/package/axios)
7
+ [![gitter chat](https://img.shields.io/gitter/room/mzabriskie/axios.svg?style=flat-square)](https://gitter.im/mzabriskie/axios)
8
+
9
+ Promise based HTTP client for the browser and node.js
10
+
11
+ ## Features
12
+
13
+ - Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser
14
+ - Make [http](http://nodejs.org/api/http.html) requests from node.js
15
+ - Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
16
+ - Intercept request and response
17
+ - Transform request and response data
18
+ - Automatic transforms for JSON data
19
+ - Client side support for protecting against [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
20
+
21
+ ## Browser Support
22
+
23
+ ![Chrome](https://raw.github.com/alrra/browser-logos/master/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/internet-explorer/internet-explorer_48x48.png) |
24
+ --- | --- | --- | --- | --- | --- |
25
+ Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 8+ ✔ |
26
+
27
+ [![Browser Matrix](https://saucelabs.com/browser-matrix/axios.svg)](https://saucelabs.com/u/axios)
28
+
29
+ ## Installing
30
+
31
+ Using cdn:
32
+
33
+ ```html
34
+ <script src="https://npmcdn.com/axios/dist/axios.min.js"></script>
35
+ ```
36
+
37
+ Using npm:
38
+
39
+ ```bash
40
+ $ npm install axios
41
+ ```
42
+
43
+ Using bower:
44
+
45
+ ```bash
46
+ $ bower install axios
47
+ ```
48
+
49
+ ## Example
50
+
51
+ Performing a `GET` request
52
+
53
+ ```js
54
+ // Make a request for a user with a given ID
55
+ axios.get('/user?ID=12345')
56
+ .then(function (response) {
57
+ console.log(response);
58
+ })
59
+ .catch(function (response) {
60
+ console.log(response);
61
+ });
62
+
63
+ // Optionally the request above could also be done as
64
+ axios.get('/user', {
65
+ params: {
66
+ ID: 12345
67
+ }
68
+ })
69
+ .then(function (response) {
70
+ console.log(response);
71
+ })
72
+ .catch(function (response) {
73
+ console.log(response);
74
+ });
75
+ ```
76
+
77
+ Performing a `POST` request
78
+
79
+ ```js
80
+ axios.post('/user', {
81
+ firstName: 'Fred',
82
+ lastName: 'Flintstone'
83
+ })
84
+ .then(function (response) {
85
+ console.log(response);
86
+ })
87
+ .catch(function (response) {
88
+ console.log(response);
89
+ });
90
+ ```
91
+
92
+ Performing multiple concurrent requests
93
+
94
+ ```js
95
+ function getUserAccount() {
96
+ return axios.get('/user/12345');
97
+ }
98
+
99
+ function getUserPermissions() {
100
+ return axios.get('/user/12345/permissions');
101
+ }
102
+
103
+ axios.all([getUserAccount(), getUserPermissions()])
104
+ .then(axios.spread(function (acct, perms) {
105
+ // Both requests are now complete
106
+ }));
107
+ ```
108
+
109
+ ## axios API
110
+
111
+ Requests can be made by passing the relevant config to `axios`.
112
+
113
+ ##### axios(config)
114
+
115
+ ```js
116
+ // Send a POST request
117
+ axios({
118
+ method: 'post',
119
+ url: '/user/12345',
120
+ data: {
121
+ firstName: 'Fred',
122
+ lastName: 'Flintstone'
123
+ }
124
+ });
125
+ ```
126
+
127
+ ##### axios(url[, config])
128
+
129
+ ```js
130
+ // Send a GET request (default method)
131
+ axios('/user/12345');
132
+ ```
133
+
134
+ ### Request method aliases
135
+
136
+ For convenience aliases have been provided for all supported request methods.
137
+
138
+ ##### axios.get(url[, config])
139
+ ##### axios.delete(url[, config])
140
+ ##### axios.head(url[, config])
141
+ ##### axios.post(url[, data[, config]])
142
+ ##### axios.put(url[, data[, config]])
143
+ ##### axios.patch(url[, data[, config]])
144
+
145
+ ###### NOTE
146
+ When using the alias methods `url`, `method`, and `data` properties don't need to be specified in config.
147
+
148
+ ### Concurrency
149
+
150
+ Helper functions for dealing with concurrent requests.
151
+
152
+ ##### axios.all(iterable)
153
+ ##### axios.spread(callback)
154
+
155
+ ### Creating an instance
156
+
157
+ You can create a new instance of axios with a custom config.
158
+
159
+ ##### axios.create([config])
160
+
161
+ ```js
162
+ var instance = axios.create({
163
+ baseURL: 'https://some-domain.com/api/',
164
+ timeout: 1000,
165
+ headers: {'X-Custom-Header': 'foobar'}
166
+ });
167
+ ```
168
+
169
+ ### Instance methods
170
+
171
+ The available instance methods are listed below. The specified config will be merged with the instance config.
172
+
173
+ ##### axios#request(config)
174
+ ##### axios#get(url[, config])
175
+ ##### axios#delete(url[, config])
176
+ ##### axios#head(url[, config])
177
+ ##### axios#post(url[, data[, config]])
178
+ ##### axios#put(url[, data[, config]])
179
+ ##### axios#patch(url[, data[, config]])
180
+
181
+ ## Request Config
182
+
183
+ These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified.
184
+
185
+ ```js
186
+ {
187
+ // `url` is the server URL that will be used for the request
188
+ url: '/user',
189
+
190
+ // `method` is the request method to be used when making the request
191
+ method: 'get', // default
192
+
193
+ // `baseURL` will be prepended to `url` unless `url` is absolute.
194
+ // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
195
+ // to methods of that instance.
196
+ baseURL: 'https://some-domain.com/api/',
197
+
198
+ // `transformRequest` allows changes to the request data before it is sent to the server
199
+ // This is only applicable for request methods 'PUT', 'POST', and 'PATCH'
200
+ // The last function in the array must return a string, an ArrayBuffer, or a Stream
201
+ transformRequest: [function (data) {
202
+ // Do whatever you want to transform the data
203
+
204
+ return data;
205
+ }],
206
+
207
+ // `transformResponse` allows changes to the response data to be made before
208
+ // it is passed to then/catch
209
+ transformResponse: [function (data) {
210
+ // Do whatever you want to transform the data
211
+
212
+ return data;
213
+ }],
214
+
215
+ // `headers` are custom headers to be sent
216
+ headers: {'X-Requested-With': 'XMLHttpRequest'},
217
+
218
+ // `params` are the URL parameters to be sent with the request
219
+ params: {
220
+ ID: 12345
221
+ },
222
+
223
+ // `paramsSerializer` is an optional function in charge of serializing `params`
224
+ // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
225
+ paramsSerializer: function(params) {
226
+ return Qs.stringify(params, {arrayFormat: 'brackets'})
227
+ },
228
+
229
+ // `data` is the data to be sent as the request body
230
+ // Only applicable for request methods 'PUT', 'POST', and 'PATCH'
231
+ // When no `transformRequest` is set, must be a string, an ArrayBuffer, a hash, or a Stream
232
+ data: {
233
+ firstName: 'Fred'
234
+ },
235
+
236
+ // `timeout` specifies the number of milliseconds before the request times out.
237
+ // If the request takes longer than `timeout`, the request will be aborted.
238
+ timeout: 1000,
239
+
240
+ // `withCredentials` indicates whether or not cross-site Access-Control requests
241
+ // should be made using credentials
242
+ withCredentials: false, // default
243
+
244
+ // `adapter` allows custom handling of requests which makes testing easier.
245
+ // Call `resolve` or `reject` and supply a valid response (see [response docs](#response-api)).
246
+ adapter: function (resolve, reject, config) {
247
+ /* ... */
248
+ },
249
+
250
+ // `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
251
+ // This will set an `Authorization` header, overwriting any existing
252
+ // `Authorization` custom headers you have set using `headers`.
253
+ auth: {
254
+ username: 'janedoe',
255
+ password: 's00pers3cret'
256
+ }
257
+
258
+ // `responseType` indicates the type of data that the server will respond with
259
+ // options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
260
+ responseType: 'json', // default
261
+
262
+ // `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
263
+ xsrfCookieName: 'XSRF-TOKEN', // default
264
+
265
+ // `xsrfHeaderName` is the name of the http header that carries the xsrf token value
266
+ xsrfHeaderName: 'X-XSRF-TOKEN', // default
267
+
268
+ // `progress` allows handling of progress events for 'POST' and 'PUT uploads'
269
+ // as well as 'GET' downloads
270
+ progress: function (progressEvent) {
271
+ // Do whatever you want with the native progress event
272
+ },
273
+
274
+ // `maxContentLength` defines the max size of the http response content allowed
275
+ maxContentLength: 2000,
276
+
277
+ // `validateStatus` defines whether to resolve or reject the promise for a given
278
+ // HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
279
+ // or `undefined`), the promise will be resolved; otherwise, the promise will be
280
+ // rejected.
281
+ validateStatus: function (status) {
282
+ return status >= 200 && status < 300; // default
283
+ }
284
+ }
285
+ ```
286
+
287
+ ## Response Schema
288
+
289
+ The response for a request contains the following information.
290
+
291
+ ```js
292
+ {
293
+ // `data` is the response that was provided by the server
294
+ data: {},
295
+
296
+ // `status` is the HTTP status code from the server response
297
+ status: 200,
298
+
299
+ // `statusText` is the HTTP status message from the server response
300
+ statusText: 'OK',
301
+
302
+ // `headers` the headers that the server responded with
303
+ headers: {},
304
+
305
+ // `config` is the config that was provided to `axios` for the request
306
+ config: {}
307
+ }
308
+ ```
309
+
310
+ When using `then` or `catch`, you will receive the response as follows:
311
+
312
+ ```js
313
+ axios.get('/user/12345')
314
+ .then(function(response) {
315
+ console.log(response.data);
316
+ console.log(response.status);
317
+ console.log(response.statusText);
318
+ console.log(response.headers);
319
+ console.log(response.config);
320
+ });
321
+ ```
322
+
323
+ ## Config Defaults
324
+
325
+ You can specify config defaults that will be applied to every request.
326
+
327
+ ### Global axios defaults
328
+
329
+ ```js
330
+ axios.defaults.baseURL = 'https://api.example.com';
331
+ axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
332
+ axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
333
+ ```
334
+
335
+ ### Custom instance defaults
336
+
337
+ ```js
338
+ // Set config defaults when creating the instance
339
+ var instance = axios.create({
340
+ baseURL: 'https://api.example.com'
341
+ });
342
+
343
+ // Alter defaults after instance has been created
344
+ instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
345
+ ```
346
+
347
+ ### Config order of precedence
348
+
349
+ Config will be merged with an order of precedence. The order is library defaults found in `lib/defaults.js`, then `defaults` property of the instance, and finally `config` argument for the request. The latter will take precedence over the former. Here's an example.
350
+
351
+ ```js
352
+ // Create an instance using the config defaults provided by the library
353
+ // At this point the timeout config value is `0` as is the default for the library
354
+ var instance = axios.create();
355
+
356
+ // Override timeout default for the library
357
+ // Now all requests will wait 2.5 seconds before timing out
358
+ instance.defaults.timeout = 2500;
359
+
360
+ // Override timeout for this request as it's known to take a long time
361
+ instance.get('/longRequest', {
362
+ timeout: 5000
363
+ });
364
+ ```
365
+
366
+ ## Interceptors
367
+
368
+ You can intercept requests or responses before they are handled by `then` or `catch`.
369
+
370
+ ```js
371
+ // Add a request interceptor
372
+ axios.interceptors.request.use(function (config) {
373
+ // Do something before request is sent
374
+ return config;
375
+ }, function (error) {
376
+ // Do something with request error
377
+ return Promise.reject(error);
378
+ });
379
+
380
+ // Add a response interceptor
381
+ axios.interceptors.response.use(function (response) {
382
+ // Do something with response data
383
+ return response;
384
+ }, function (error) {
385
+ // Do something with response error
386
+ return Promise.reject(error);
387
+ });
388
+ ```
389
+
390
+ If you may need to remove an interceptor later you can.
391
+
392
+ ```js
393
+ var myInterceptor = axios.interceptors.request.use(function () {/*...*/});
394
+ axios.interceptors.request.eject(myInterceptor);
395
+ ```
396
+
397
+ You can add interceptors to a custom instance of axios.
398
+
399
+ ```js
400
+ var instance = axios.create();
401
+ instance.interceptors.request.use(function () {/*...*/});
402
+ ```
403
+
404
+ ## Handling Errors
405
+
406
+ ```js
407
+ axios.get('/user/12345')
408
+ .catch(function (response) {
409
+ if (response instanceof Error) {
410
+ // Something happened in setting up the request that triggered an Error
411
+ console.log('Error', response.message);
412
+ } else {
413
+ // The request was made, but the server responded with a status code
414
+ // that falls out of the range of 2xx
415
+ console.log(response.data);
416
+ console.log(response.status);
417
+ console.log(response.headers);
418
+ console.log(response.config);
419
+ }
420
+ });
421
+ ```
422
+
423
+ You can define a custom HTTP status code error range using the `validateStatus` config option.
424
+
425
+ ```js
426
+ axios.get('/user/12345', {
427
+ validateStatus: function (status) {
428
+ return status < 500; // Reject only if the status code is greater than or equal to 500
429
+ }
430
+ })
431
+ ```
432
+
433
+ ## Semver
434
+
435
+ Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes.
436
+
437
+ ## Promises
438
+
439
+ axios depends on a native ES6 Promise implementation to be [supported](http://caniuse.com/promises).
440
+ If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).
441
+
442
+ ## TypeScript
443
+ axios includes a [TypeScript](http://typescriptlang.org) definition.
444
+ ```typescript
445
+ /// <reference path="axios.d.ts" />
446
+ import * as axios from 'axios';
447
+ axios.get('/user?ID=12345');
448
+ ```
449
+
450
+ ## Resources
451
+
452
+ * [Changelog](https://github.com/mzabriskie/axios/blob/master/CHANGELOG.md)
453
+ * [Ecosystem](https://github.com/mzabriskie/axios/blob/master/ECOSYSTEM.md)
454
+ * [Contributing Guide](https://github.com/mzabriskie/axios/blob/master/CONTRIBUTING.md)
455
+ * [Code of Conduct](https://github.com/mzabriskie/axios/blob/master/CODE_OF_CONDUCT.md)
456
+
457
+ ## Credits
458
+
459
+ axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) provided in [Angular](https://angularjs.org/). Ultimately axios is an effort to provide a standalone `$http`-like service for use outside of Angular.
460
+
461
+ ## License
462
+
463
+ MIT
package/component.json ADDED
@@ -0,0 +1 @@
1
+ {"name":"axios","version":"0.9.1","description":"Promise based HTTP client for the browser and node.js","keywords":["xhr","http","ajax","promise","node"],"repo":{"type":"git","url":"https://github.com/mzabriskie/axios.git"},"license":"MIT"}
package/dist/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- /* axios v0.11.0 | (c) 2016 by Matt Zabriskie */
1
+ /* axios v0.11.1 | (c) 2016 by Matt Zabriskie */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory();
@@ -141,6 +141,7 @@ return /******/ (function(modules) { // webpackBootstrap
141
141
 
142
142
  var defaultInstance = new Axios(defaults);
143
143
  var axios = module.exports = bind(Axios.prototype.request, defaultInstance);
144
+ module.exports.Axios = Axios;
144
145
 
145
146
  // Expose properties from defaultInstance
146
147
  axios.defaults = defaultInstance.defaults;
@@ -293,7 +294,7 @@ return /******/ (function(modules) { // webpackBootstrap
293
294
  * @returns {boolean} True if value is an FormData, otherwise false
294
295
  */
295
296
  function isFormData(val) {
296
- return toString.call(val) === '[object FormData]';
297
+ return (typeof FormData !== 'undefined') && (val instanceof FormData);
297
298
  }
298
299
 
299
300
  /**
@@ -599,6 +600,8 @@ return /******/ (function(modules) { // webpackBootstrap
599
600
  request = new window.XDomainRequest();
600
601
  loadEvent = 'onload';
601
602
  xDomain = true;
603
+ request.onprogress = function handleProgress() {};
604
+ request.ontimeout = function handleTimeout() {};
602
605
  }
603
606
 
604
607
  // HTTP basic authentication
@@ -613,10 +616,6 @@ return /******/ (function(modules) { // webpackBootstrap
613
616
  // Set the request timeout in MS
614
617
  request.timeout = config.timeout;
615
618
 
616
- // For IE 9 CORS support.
617
- request.onprogress = function handleProgress() {};
618
- request.ontimeout = function handleTimeout() {};
619
-
620
619
  // Listen for ready state
621
620
  request[loadEvent] = function handleLoad() {
622
621
  if (!request || (request.readyState !== 4 && !xDomain)) {