axios 0.18.0 → 0.19.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,16 +1,180 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.19.1 (Jan 7, 2020)
4
+
5
+ Fixes and Functionality:
6
+
7
+ - Fixing invalid agent issue (#1904)[https://github.com/axios/axios/pull/1904]
8
+ - Fix ignore set withCredentials false (#2582)[https://github.com/axios/axios/pull/2582]
9
+ - Delete useless default to hash (#2458)[https://github.com/axios/axios/pull/2458]
10
+ - Fix HTTP/HTTPs agents passing to follow-redirect (#1904)[https://github.com/axios/axios/pull/1904]
11
+ - Fix ignore set withCredentials false (#2582)[https://github.com/axios/axios/pull/2582]
12
+ - Fix CI build failure (#2570)[https://github.com/axios/axios/pull/2570]
13
+ - Remove dependency on is-buffer from package.json (#1816)[https://github.com/axios/axios/pull/1816]
14
+ - Adding options typings (#2341)[https://github.com/axios/axios/pull/2341]
15
+ - Adding Typescript HTTP method definition for LINK and UNLINK. (#2444)[https://github.com/axios/axios/pull/2444]
16
+ - Update dist with newest changes, fixes Custom Attributes issue
17
+ - Change syntax to see if build passes (#2488)[https://github.com/axios/axios/pull/2488]
18
+ - Update Webpack + deps, remove now unnecessary polyfills (#2410)[https://github.com/axios/axios/pull/2410]
19
+ - Fix to prevent XSS, throw an error when the URL contains a JS script (#2464)[https://github.com/axios/axios/pull/2464]
20
+ - Add custom timeout error copy in config (#2275)[https://github.com/axios/axios/pull/2275]
21
+ - Add error toJSON example (#2466)[https://github.com/axios/axios/pull/2466]
22
+ - Fixing Vulnerability A Fortify Scan finds a critical Cross-Site Scrip… (#2451)[https://github.com/axios/axios/pull/2451]
23
+ - Fixing subdomain handling on no_proxy (#2442)[https://github.com/axios/axios/pull/2442]
24
+ - Make redirection from HTTP to HTTPS work (#2426)[https://github.com/axios/axios/pull/2426] and (#2547)[https://github.com/axios/axios/pull/2547]
25
+ - Add toJSON property to AxiosError type (#2427)[https://github.com/axios/axios/pull/2427]
26
+ - Fixing socket hang up error on node side for slow response. (#1752)[https://github.com/axios/axios/pull/1752]
27
+ - Alternative syntax to send data into the body (#2317)[https://github.com/axios/axios/pull/2317]
28
+ - Fixing custom config options (#2207)[https://github.com/axios/axios/pull/2207]
29
+ - Fixing set `config.method` after mergeConfig for Axios.prototype.request (#2383)[https://github.com/axios/axios/pull/2383]
30
+ - Axios create url bug (#2290)[https://github.com/axios/axios/pull/2290]
31
+ - Do not modify config.url when using a relative baseURL (resolves [#1628](https://github.com/axios/axios/issues/1098)) (#2391)[https://github.com/axios/axios/pull/2391]
32
+ - Add typescript HTTP method definition for LINK and UNLINK ([#2444](https://github.com/axios/axios/pull/2444))
33
+
34
+ Internal:
35
+
36
+ - Revert "Update Webpack + deps, remove now unnecessary polyfills" (#2479)[https://github.com/axios/axios/pull/2479]
37
+ - Order of if/else blocks is causing unit tests mocking XHR. (#2201)[https://github.com/axios/axios/pull/2201]
38
+ - Add license badge (#2446)[https://github.com/axios/axios/pull/2446]
39
+ - Fix travis CI build [#2386](https://github.com/axios/axios/pull/2386)
40
+ - Fix cancellation error on build master. #2290 #2207 (#2407)[https://github.com/axios/axios/pull/2407]
41
+
42
+ Documentation:
43
+
44
+ - Fixing typo in CHANGELOG.md: s/Functionallity/Functionality (#2639)[https://github.com/axios/axios/pull/2639]
45
+ - Fix badge, use master branch (#2538)[https://github.com/axios/axios/pull/2538]
46
+ - Fix typo in changelog [#2193](https://github.com/axios/axios/pull/2193)
47
+ - Document fix (#2514)[https://github.com/axios/axios/pull/2514]
48
+ - Update docs with no_proxy change, issue #2484 (#2513)[https://github.com/axios/axios/pull/2513]
49
+ - Fixing missing words in docs template (#2259)[https://github.com/axios/axios/pull/2259]
50
+ - 🐛Fix request finally documentation in README (#2189)[https://github.com/axios/axios/pull/2189]
51
+ - updating spelling and adding link to docs (#2212)[https://github.com/axios/axios/pull/2212]
52
+ - docs: minor tweak (#2404)[https://github.com/axios/axios/pull/2404]
53
+ - Update response interceptor docs (#2399)[https://github.com/axios/axios/pull/2399]
54
+ - Update README.md (#2504)[https://github.com/axios/axios/pull/2504]
55
+ - Fix word 'sintaxe' to 'syntax' in README.md (#2432)[https://github.com/axios/axios/pull/2432]
56
+ - upadating README: notes on CommonJS autocomplete (#2256)[https://github.com/axios/axios/pull/2256]
57
+ - Fix grammar in README.md (#2271)[https://github.com/axios/axios/pull/2271]
58
+ - Doc fixes, minor examples cleanup (#2198)[https://github.com/axios/axios/pull/2198]
59
+
60
+ ### 0.19.0 (May 30, 2019)
61
+
62
+ Fixes and Functionality:
63
+
64
+ - Added support for no_proxy env variable ([#1693](https://github.com/axios/axios/pull/1693/files)) - Chance Dickson
65
+ - Unzip response body only for statuses != 204 ([#1129](https://github.com/axios/axios/pull/1129)) - drawski
66
+ - Destroy stream on exceeding maxContentLength (fixes [#1098](https://github.com/axios/axios/issues/1098)) ([#1485](https://github.com/axios/axios/pull/1485)) - Gadzhi Gadzhiev
67
+ - Makes Axios error generic to use AxiosResponse ([#1738](https://github.com/axios/axios/pull/1738)) - Suman Lama
68
+ - Fixing Mocha tests by locking follow-redirects version to 1.5.10 ([#1993](https://github.com/axios/axios/pull/1993)) - grumblerchester
69
+ - Allow uppercase methods in typings. ([#1781](https://github.com/axios/axios/pull/1781)) - Ken Powers
70
+ - Fixing building url with hash mark ([#1771](https://github.com/axios/axios/pull/1771)) - Anatoly Ryabov
71
+ - This commit fix building url with hash map (fragment identifier) when parameters are present: they must not be added after `#`, because client cut everything after `#`
72
+ - Preserve HTTP method when following redirect ([#1758](https://github.com/axios/axios/pull/1758)) - Rikki Gibson
73
+ - Add `getUri` signature to TypeScript definition. ([#1736](https://github.com/axios/axios/pull/1736)) - Alexander Trauzzi
74
+ - Adding isAxiosError flag to errors thrown by axios ([#1419](https://github.com/axios/axios/pull/1419)) - Ayush Gupta
75
+
76
+ Internal:
77
+
78
+ - Fixing .eslintrc without extension ([#1789](https://github.com/axios/axios/pull/1789)) - Manoel
79
+ - Fix failing SauceLabs tests by updating configuration - Emily Morehouse
80
+ - Add issue templates - Emily Morehouse
81
+
82
+ Documentation:
83
+
84
+ - Consistent coding style in README ([#1787](https://github.com/axios/axios/pull/1787)) - Ali Servet Donmez
85
+ - Add information about auth parameter to README ([#2166](https://github.com/axios/axios/pull/2166)) - xlaguna
86
+ - Add DELETE to list of methods that allow data as a config option ([#2169](https://github.com/axios/axios/pull/2169)) - Daniela Borges Matos de Carvalho
87
+ - Update ECOSYSTEM.md - Add Axios Endpoints ([#2176](https://github.com/axios/axios/pull/2176)) - Renan
88
+ - Add r2curl in ECOSYSTEM ([#2141](https://github.com/axios/axios/pull/2141)) - 유용우 / CX
89
+ - Update README.md - Add instructions for installing with yarn ([#2036](https://github.com/axios/axios/pull/2036)) - Victor Hermes
90
+ - Fixing spacing for README.md ([#2066](https://github.com/axios/axios/pull/2066)) - Josh McCarty
91
+ - Update README.md. - Change `.then` to `.finally` in example code ([#2090](https://github.com/axios/axios/pull/2090)) - Omar Cai
92
+ - Clarify what values responseType can have in Node ([#2121](https://github.com/axios/axios/pull/2121)) - Tyler Breisacher
93
+ - docs(ECOSYSTEM): add axios-api-versioning ([#2020](https://github.com/axios/axios/pull/2020)) - Weffe
94
+ - It seems that `responseType: 'blob'` doesn't actually work in Node (when I tried using it, response.data was a string, not a Blob, since Node doesn't have Blobs), so this clarifies that this option should only be used in the browser
95
+ - Update README.md. - Add Querystring library note ([#1896](https://github.com/axios/axios/pull/1896)) - Dmitriy Eroshenko
96
+ - Add react-hooks-axios to Libraries section of ECOSYSTEM.md ([#1925](https://github.com/axios/axios/pull/1925)) - Cody Chan
97
+ - Clarify in README that default timeout is 0 (no timeout) ([#1750](https://github.com/axios/axios/pull/1750)) - Ben Standefer
98
+
99
+ ### 0.19.0-beta.1 (Aug 9, 2018)
100
+
101
+ **NOTE:** This is a beta version of this release. There may be functionality that is broken in
102
+ certain browsers, though we suspect that builds are hanging and not erroring. See
103
+ https://saucelabs.com/u/axios for the most up-to-date information.
104
+
105
+ New Functionality:
106
+
107
+ - Add getUri method ([#1712](https://github.com/axios/axios/issues/1712))
108
+ - Add support for no_proxy env variable ([#1693](https://github.com/axios/axios/issues/1693))
109
+ - Add toJSON to decorated Axios errors to faciliate serialization ([#1625](https://github.com/axios/axios/issues/1625))
110
+ - Add second then on axios call ([#1623](https://github.com/axios/axios/issues/1623))
111
+ - Typings: allow custom return types
112
+ - Add option to specify character set in responses (with http adapter)
113
+
114
+ Fixes:
115
+
116
+ - Fix Keep defaults local to instance ([#385](https://github.com/axios/axios/issues/385))
117
+ - Correctly catch exception in http test ([#1475](https://github.com/axios/axios/issues/1475))
118
+ - Fix accept header normalization ([#1698](https://github.com/axios/axios/issues/1698))
119
+ - Fix http adapter to allow HTTPS connections via HTTP ([#959](https://github.com/axios/axios/issues/959))
120
+ - Fix Removes usage of deprecated Buffer constructor. ([#1555](https://github.com/axios/axios/issues/1555), [#1622](https://github.com/axios/axios/issues/1622))
121
+ - Fix defaults to use httpAdapter if available ([#1285](https://github.com/axios/axios/issues/1285))
122
+ - Fixing defaults to use httpAdapter if available
123
+ - Use a safer, cross-platform method to detect the Node environment
124
+ - Fix Reject promise if request is cancelled by the browser ([#537](https://github.com/axios/axios/issues/537))
125
+ - [Typescript] Fix missing type parameters on delete/head methods
126
+ - [NS]: Send `false` flag isStandardBrowserEnv for Nativescript
127
+ - Fix missing type parameters on delete/head
128
+ - Fix Default method for an instance always overwritten by get
129
+ - Fix type error when socketPath option in AxiosRequestConfig
130
+ - Capture errors on request data streams
131
+ - Decorate resolve and reject to clear timeout in all cases
132
+
133
+ Huge thanks to everyone who contributed to this release via code (authors listed
134
+ below) or via reviews and triaging on GitHub:
135
+
136
+ - Andrew Scott <ascott18@gmail.com>
137
+ - Anthony Gauthier <antho325@hotmail.com>
138
+ - arpit <arpit2438735@gmail.com>
139
+ - ascott18
140
+ - Benedikt Rötsch <axe312ger@users.noreply.github.com>
141
+ - Chance Dickson <me@chancedickson.com>
142
+ - Dave Stewart <info@davestewart.co.uk>
143
+ - Deric Cain <deric.cain@gmail.com>
144
+ - Guillaume Briday <guillaumebriday@gmail.com>
145
+ - Jacob Wejendorp <jacob@wejendorp.dk>
146
+ - Jim Lynch <mrdotjim@gmail.com>
147
+ - johntron
148
+ - Justin Beckwith <beckwith@google.com>
149
+ - Justin Beckwith <justin.beckwith@gmail.com>
150
+ - Khaled Garbaya <khaledgarbaya@gmail.com>
151
+ - Lim Jing Rong <jjingrong@users.noreply.github.com>
152
+ - Mark van den Broek <mvdnbrk@gmail.com>
153
+ - Martti Laine <martti@codeclown.net>
154
+ - mattridley
155
+ - mattridley <matt.r@joinblink.com>
156
+ - Nicolas Del Valle <nicolas.delvalle@gmail.com>
157
+ - Nilegfx
158
+ - pbarbiero
159
+ - Rikki Gibson <rikkigibson@gmail.com>
160
+ - Sako Hartounian <sakohartounian@yahoo.com>
161
+ - Shane Fitzpatrick <fitzpasd@gmail.com>
162
+ - Stephan Schneider <stephanschndr@gmail.com>
163
+ - Steven <steven@ceriously.com>
164
+ - Tim Garthwaite <tim.garthwaite@jibo.com>
165
+ - Tim Johns <timjohns@yahoo.com>
166
+ - Yutaro Miyazaki <yutaro@studio-rubbish.com>
167
+
3
168
  ### 0.18.0 (Feb 19, 2018)
4
169
 
5
170
  - Adding support for UNIX Sockets when running with Node.js ([#1070](https://github.com/axios/axios/pull/1070))
6
171
  - Fixing typings ([#1177](https://github.com/axios/axios/pull/1177)):
7
- - AxiosRequestConfig.proxy: allows type false
8
- - AxiosProxyConfig: added auth field
172
+ - AxiosRequestConfig.proxy: allows type false
173
+ - AxiosProxyConfig: added auth field
9
174
  - Adding function signature in AxiosInstance interface so AxiosInstance can be invoked ([#1192](https://github.com/axios/axios/pull/1192), [#1254](https://github.com/axios/axios/pull/1254))
10
175
  - Allowing maxContentLength to pass through to redirected calls as maxBodyLength in follow-redirects config ([#1287](https://github.com/axios/axios/pull/1287))
11
176
  - Fixing configuration when using an instance - method can now be set ([#1342](https://github.com/axios/axios/pull/1342))
12
177
 
13
-
14
178
  ### 0.17.1 (Nov 11, 2017)
15
179
 
16
180
  - Fixing issue with web workers ([#1160](https://github.com/axios/axios/pull/1160))
package/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # axios
2
2
 
3
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/axios/axios.svg?style=flat-square)](https://travis-ci.org/axios/axios)
4
+ [![build status](https://img.shields.io/travis/axios/axios/master.svg?style=flat-square)](https://travis-ci.org/axios/axios)
5
5
  [![code coverage](https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square)](https://coveralls.io/r/mzabriskie/axios)
6
+ [![install size](https://packagephobia.now.sh/badge?p=axios)](https://packagephobia.now.sh/result?p=axios)
6
7
  [![npm downloads](https://img.shields.io/npm/dm/axios.svg?style=flat-square)](http://npm-stat.com/charts.html?package=axios)
7
8
  [![gitter chat](https://img.shields.io/gitter/room/mzabriskie/axios.svg?style=flat-square)](https://gitter.im/mzabriskie/axios)
8
9
  [![code helpers](https://www.codetriage.com/axios/axios/badges/users.svg)](https://www.codetriage.com/axios/axios)
@@ -24,7 +25,7 @@ Promise based HTTP client for the browser and node.js
24
25
 
25
26
  ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |
26
27
  --- | --- | --- | --- | --- | --- |
27
- Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 8+ ✔ |
28
+ Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
28
29
 
29
30
  [![Browser Matrix](https://saucelabs.com/open_sauce/build_matrix/axios.svg)](https://saucelabs.com/u/axios)
30
31
 
@@ -42,6 +43,12 @@ Using bower:
42
43
  $ bower install axios
43
44
  ```
44
45
 
46
+ Using yarn:
47
+
48
+ ```bash
49
+ $ yarn add axios
50
+ ```
51
+
45
52
  Using cdn:
46
53
 
47
54
  ```html
@@ -50,16 +57,32 @@ Using cdn:
50
57
 
51
58
  ## Example
52
59
 
60
+ ### note: CommonJS usage
61
+ In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with `require()` use the following approach:
62
+
63
+ ```js
64
+ const axios = require('axios').default;
65
+
66
+ // axios.<method> will now provide autocomplete and parameter typings
67
+ ```
68
+
53
69
  Performing a `GET` request
54
70
 
55
71
  ```js
72
+ const axios = require('axios');
73
+
56
74
  // Make a request for a user with a given ID
57
75
  axios.get('/user?ID=12345')
58
76
  .then(function (response) {
77
+ // handle success
59
78
  console.log(response);
60
79
  })
61
80
  .catch(function (error) {
81
+ // handle error
62
82
  console.log(error);
83
+ })
84
+ .finally(function () {
85
+ // always executed
63
86
  });
64
87
 
65
88
  // Optionally the request above could also be done as
@@ -73,9 +96,25 @@ axios.get('/user', {
73
96
  })
74
97
  .catch(function (error) {
75
98
  console.log(error);
76
- });
99
+ })
100
+ .finally(function () {
101
+ // always executed
102
+ });
103
+
104
+ // Want to use async/await? Add the `async` keyword to your outer function/method.
105
+ async function getUser() {
106
+ try {
107
+ const response = await axios.get('/user?ID=12345');
108
+ console.log(response);
109
+ } catch (error) {
110
+ console.error(error);
111
+ }
112
+ }
77
113
  ```
78
114
 
115
+ > **NOTE:** `async/await` is part of ECMAScript 2017 and is not supported in Internet
116
+ > Explorer and older browsers, so use with caution.
117
+
79
118
  Performing a `POST` request
80
119
 
81
120
  ```js
@@ -129,13 +168,13 @@ axios({
129
168
  ```js
130
169
  // GET request for remote image
131
170
  axios({
132
- method:'get',
133
- url:'http://bit.ly/2mTM3nY',
134
- responseType:'stream'
171
+ method: 'get',
172
+ url: 'http://bit.ly/2mTM3nY',
173
+ responseType: 'stream'
135
174
  })
136
- .then(function(response) {
137
- response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
138
- });
175
+ .then(function (response) {
176
+ response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
177
+ });
139
178
  ```
140
179
 
141
180
  ##### axios(url[, config])
@@ -175,7 +214,7 @@ You can create a new instance of axios with a custom config.
175
214
  ##### axios.create([config])
176
215
 
177
216
  ```js
178
- var instance = axios.create({
217
+ const instance = axios.create({
179
218
  baseURL: 'https://some-domain.com/api/',
180
219
  timeout: 1000,
181
220
  headers: {'X-Custom-Header': 'foobar'}
@@ -194,6 +233,7 @@ The available instance methods are listed below. The specified config will be me
194
233
  ##### axios#post(url[, data[, config]])
195
234
  ##### axios#put(url[, data[, config]])
196
235
  ##### axios#patch(url[, data[, config]])
236
+ ##### axios#getUri([config])
197
237
 
198
238
  ## Request Config
199
239
 
@@ -213,7 +253,7 @@ These are the available config options for making requests. Only the `url` is re
213
253
  baseURL: 'https://some-domain.com/api/',
214
254
 
215
255
  // `transformRequest` allows changes to the request data before it is sent to the server
216
- // This is only applicable for request methods 'PUT', 'POST', and 'PATCH'
256
+ // This is only applicable for request methods 'PUT', 'POST', 'PATCH' and 'DELETE'
217
257
  // The last function in the array must return a string or an instance of Buffer, ArrayBuffer,
218
258
  // FormData or Stream
219
259
  // You may modify the headers object.
@@ -242,7 +282,7 @@ These are the available config options for making requests. Only the `url` is re
242
282
 
243
283
  // `paramsSerializer` is an optional function in charge of serializing `params`
244
284
  // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
245
- paramsSerializer: function(params) {
285
+ paramsSerializer: function (params) {
246
286
  return Qs.stringify(params, {arrayFormat: 'brackets'})
247
287
  },
248
288
 
@@ -255,10 +295,15 @@ These are the available config options for making requests. Only the `url` is re
255
295
  data: {
256
296
  firstName: 'Fred'
257
297
  },
298
+
299
+ // syntax alternative to send data into the body
300
+ // method post
301
+ // only the value is sent, not the key
302
+ data: 'Country=Brasil&City=Belo Horizonte',
258
303
 
259
304
  // `timeout` specifies the number of milliseconds before the request times out.
260
305
  // If the request takes longer than `timeout`, the request will be aborted.
261
- timeout: 1000,
306
+ timeout: 1000, // default is `0` (no timeout)
262
307
 
263
308
  // `withCredentials` indicates whether or not cross-site Access-Control requests
264
309
  // should be made using credentials
@@ -273,15 +318,22 @@ These are the available config options for making requests. Only the `url` is re
273
318
  // `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
274
319
  // This will set an `Authorization` header, overwriting any existing
275
320
  // `Authorization` custom headers you have set using `headers`.
321
+ // Please note that only HTTP Basic auth is configurable through this parameter.
322
+ // For Bearer tokens and such, use `Authorization` custom headers instead.
276
323
  auth: {
277
324
  username: 'janedoe',
278
325
  password: 's00pers3cret'
279
326
  },
280
327
 
281
328
  // `responseType` indicates the type of data that the server will respond with
282
- // options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'
329
+ // options are: 'arraybuffer', 'document', 'json', 'text', 'stream'
330
+ // browser only: 'blob'
283
331
  responseType: 'json', // default
284
332
 
333
+ // `responseEncoding` indicates encoding to use for decoding responses
334
+ // Note: Ignored for `responseType` of 'stream' or client-side requests
335
+ responseEncoding: 'utf8', // default
336
+
285
337
  // `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
286
338
  xsrfCookieName: 'XSRF-TOKEN', // default
287
339
 
@@ -298,7 +350,7 @@ These are the available config options for making requests. Only the `url` is re
298
350
  // Do whatever you want with the native progress event
299
351
  },
300
352
 
301
- // `maxContentLength` defines the max size of the http response content allowed
353
+ // `maxContentLength` defines the max size of the http response content in bytes allowed
302
354
  maxContentLength: 2000,
303
355
 
304
356
  // `validateStatus` defines whether to resolve or reject the promise for a given
@@ -325,7 +377,11 @@ These are the available config options for making requests. Only the `url` is re
325
377
  httpAgent: new http.Agent({ keepAlive: true }),
326
378
  httpsAgent: new https.Agent({ keepAlive: true }),
327
379
 
328
- // 'proxy' defines the hostname and port of the proxy server
380
+ // 'proxy' defines the hostname and port of the proxy server.
381
+ // You can also define your proxy using the conventional `http_proxy` and
382
+ // `https_proxy` environment variables. If you are using environment variables
383
+ // for your proxy configuration, you can also define a `no_proxy` environment
384
+ // variable as a comma-separated list of domains that should not be proxied.
329
385
  // Use `false` to disable proxies, ignoring environment variables.
330
386
  // `auth` indicates that HTTP Basic auth should be used to connect to the proxy, and
331
387
  // supplies credentials.
@@ -371,7 +427,7 @@ The response for a request contains the following information.
371
427
 
372
428
  // `request` is the request that generated this response
373
429
  // It is the last ClientRequest instance in node.js (in redirects)
374
- // and an XMLHttpRequest instance the browser
430
+ // and an XMLHttpRequest instance in the browser
375
431
  request: {}
376
432
  }
377
433
  ```
@@ -380,7 +436,7 @@ When using `then`, you will receive the response as follows:
380
436
 
381
437
  ```js
382
438
  axios.get('/user/12345')
383
- .then(function(response) {
439
+ .then(function (response) {
384
440
  console.log(response.data);
385
441
  console.log(response.status);
386
442
  console.log(response.statusText);
@@ -407,7 +463,7 @@ axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded
407
463
 
408
464
  ```js
409
465
  // Set config defaults when creating the instance
410
- var instance = axios.create({
466
+ const instance = axios.create({
411
467
  baseURL: 'https://api.example.com'
412
468
  });
413
469
 
@@ -422,10 +478,10 @@ Config will be merged with an order of precedence. The order is library defaults
422
478
  ```js
423
479
  // Create an instance using the config defaults provided by the library
424
480
  // At this point the timeout config value is `0` as is the default for the library
425
- var instance = axios.create();
481
+ const instance = axios.create();
426
482
 
427
483
  // Override timeout default for the library
428
- // Now all requests will wait 2.5 seconds before timing out
484
+ // Now all requests using this instance will wait 2.5 seconds before timing out
429
485
  instance.defaults.timeout = 2500;
430
486
 
431
487
  // Override timeout for this request as it's known to take a long time
@@ -450,25 +506,27 @@ axios.interceptors.request.use(function (config) {
450
506
 
451
507
  // Add a response interceptor
452
508
  axios.interceptors.response.use(function (response) {
509
+ // Any status code that lie within the range of 2xx cause this function to trigger
453
510
  // Do something with response data
454
511
  return response;
455
512
  }, function (error) {
513
+ // Any status codes that falls outside the range of 2xx cause this function to trigger
456
514
  // Do something with response error
457
515
  return Promise.reject(error);
458
516
  });
459
517
  ```
460
518
 
461
- If you may need to remove an interceptor later you can.
519
+ If you need to remove an interceptor later you can.
462
520
 
463
521
  ```js
464
- var myInterceptor = axios.interceptors.request.use(function () {/*...*/});
522
+ const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
465
523
  axios.interceptors.request.eject(myInterceptor);
466
524
  ```
467
525
 
468
526
  You can add interceptors to a custom instance of axios.
469
527
 
470
528
  ```js
471
- var instance = axios.create();
529
+ const instance = axios.create();
472
530
  instance.interceptors.request.use(function () {/*...*/});
473
531
  ```
474
532
 
@@ -496,7 +554,7 @@ axios.get('/user/12345')
496
554
  });
497
555
  ```
498
556
 
499
- You can define a custom HTTP status code error range using the `validateStatus` config option.
557
+ Using the `validateStatus` config option, you can define HTTP code(s) that should throw an error.
500
558
 
501
559
  ```js
502
560
  axios.get('/user/12345', {
@@ -506,6 +564,15 @@ axios.get('/user/12345', {
506
564
  })
507
565
  ```
508
566
 
567
+ Using `toJSON` you get an object with more information about the HTTP error.
568
+
569
+ ```js
570
+ axios.get('/user/12345')
571
+ .catch(function (error) {
572
+ console.log(error.toJSON());
573
+ });
574
+ ```
575
+
509
576
  ## Cancellation
510
577
 
511
578
  You can cancel a request using a *cancel token*.
@@ -515,12 +582,12 @@ You can cancel a request using a *cancel token*.
515
582
  You can create a cancel token using the `CancelToken.source` factory as shown below:
516
583
 
517
584
  ```js
518
- var CancelToken = axios.CancelToken;
519
- var source = CancelToken.source();
585
+ const CancelToken = axios.CancelToken;
586
+ const source = CancelToken.source();
520
587
 
521
588
  axios.get('/user/12345', {
522
589
  cancelToken: source.token
523
- }).catch(function(thrown) {
590
+ }).catch(function (thrown) {
524
591
  if (axios.isCancel(thrown)) {
525
592
  console.log('Request canceled', thrown.message);
526
593
  } else {
@@ -541,8 +608,8 @@ source.cancel('Operation canceled by the user.');
541
608
  You can also create a cancel token by passing an executor function to the `CancelToken` constructor:
542
609
 
543
610
  ```js
544
- var CancelToken = axios.CancelToken;
545
- var cancel;
611
+ const CancelToken = axios.CancelToken;
612
+ let cancel;
546
613
 
547
614
  axios.get('/user/12345', {
548
615
  cancelToken: new CancelToken(function executor(c) {
@@ -566,7 +633,7 @@ By default, axios serializes JavaScript objects to `JSON`. To send data in the `
566
633
  In a browser, you can use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API as follows:
567
634
 
568
635
  ```js
569
- var params = new URLSearchParams();
636
+ const params = new URLSearchParams();
570
637
  params.append('param1', 'value1');
571
638
  params.append('param2', 'value2');
572
639
  axios.post('/foo', params);
@@ -577,21 +644,38 @@ axios.post('/foo', params);
577
644
  Alternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library:
578
645
 
579
646
  ```js
580
- var qs = require('qs');
647
+ const qs = require('qs');
581
648
  axios.post('/foo', qs.stringify({ 'bar': 123 }));
582
649
  ```
583
650
 
651
+ Or in another way (ES6),
652
+
653
+ ```js
654
+ import qs from 'qs';
655
+ const data = { 'bar': 123 };
656
+ const options = {
657
+ method: 'POST',
658
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
659
+ data: qs.stringify(data),
660
+ url,
661
+ };
662
+ axios(options);
663
+ ```
664
+
584
665
  ### Node.js
585
666
 
586
667
  In node.js, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
587
668
 
588
669
  ```js
589
- var querystring = require('querystring');
670
+ const querystring = require('querystring');
590
671
  axios.post('http://something.com/', querystring.stringify({ foo: 'bar' }));
591
672
  ```
592
673
 
593
674
  You can also use the [`qs`](https://github.com/ljharb/qs) library.
594
675
 
676
+ ###### NOTE
677
+ The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has known issues with that use case (https://github.com/nodejs/node-v0.x-archive/issues/1665).
678
+
595
679
  ## Semver
596
680
 
597
681
  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.
@@ -622,4 +706,4 @@ axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/
622
706
 
623
707
  ## License
624
708
 
625
- MIT
709
+ [MIT](LICENSE)