axios 0.26.1 → 0.27.0

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.
package/CHANGELOG.md CHANGED
@@ -1,9 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.27.0 (April 19, 2022)
4
+
5
+ Breaking changes:
6
+ - New toFormData helper function that allows the implementor to pass an object and allow axios to convert it to FormData ([#3757](https://github.com/axios/axios/pull/3757))
7
+ - Removed functionality that removed the the `Content-Type` request header when passing FormData ([#3785](https://github.com/axios/axios/pull/3785))
8
+ - **(*)** Refactored error handling implementing AxiosError as a constructor, this is a large change to error handling on the whole ([#3645](https://github.com/axios/axios/pull/3645))
9
+ - Separated responsibility for FormData instantiation between `transformRequest` and `toFormData` ([#4470](https://github.com/axios/axios/pull/4470))
10
+ - **(*)** Improved and fixed multiple issues with FormData support ([#4448](https://github.com/axios/axios/pull/4448))
11
+
12
+ QOL and DevX improvements:
13
+ - Added a multipart/form-data testing playground allowing contributors to debug changes easily ([#4465](https://github.com/axios/axios/pull/4465))
14
+
15
+ Fixes and Functionality:
16
+ - Refactored project file structure to avoid circular imports ([#4515](https://github.com/axios/axios/pull/4516)) & ([#4516](https://github.com/axios/axios/pull/4516))
17
+ - Bumped follow-redirects to ^1.14.9 ([#4562](https://github.com/axios/axios/pull/4562))
18
+
19
+ Internal and Tests:
20
+ - Updated dev dependencies to latest version
21
+
22
+ Documentation:
23
+ - Fixing incorrect link in changelog ([#4551](https://github.com/axios/axios/pull/4551))
24
+
25
+ Notes:
26
+ - **(*)** Please read these pull requests before updating, these changes are very impactful and far reaching.
27
+
3
28
  ### 0.26.1 (March 9, 2022)
4
29
 
5
30
  Fixes and Functionality:
6
- - Refactored project file structure to avoid circular imports ([##4220](https://github.com/axios/axios/pull/#4220))
31
+ - Refactored project file structure to avoid circular imports ([#4220](https://github.com/axios/axios/pull/4220))
7
32
 
8
33
  ### 0.26.0 (February 13, 2022)
9
34
 
@@ -11,7 +36,7 @@ Fixes and Functionality:
11
36
  - Fixed The timeoutErrorMessage property in config not work with Node.js ([#3581](https://github.com/axios/axios/pull/3581))
12
37
  - Added errors to be displayed when the query parsing process itself fails ([#3961](https://github.com/axios/axios/pull/3961))
13
38
  - Fix/remove url required ([#4426](https://github.com/axios/axios/pull/4426))
14
- - Update follow-redirects dependency due to Vurnerbility ([#4462](https://github.com/axios/axios/pull/4462))
39
+ - Update follow-redirects dependency due to Vulnerability ([#4462](https://github.com/axios/axios/pull/4462))
15
40
  - Bump karma from 6.3.11 to 6.3.14 ([#4461](https://github.com/axios/axios/pull/4461))
16
41
  - Bump follow-redirects from 1.14.7 to 1.14.8 ([#4473](https://github.com/axios/axios/pull/4473))
17
42
 
@@ -19,7 +44,7 @@ Fixes and Functionality:
19
44
 
20
45
  Breaking changes:
21
46
  - Fixing maxBodyLength enforcement ([#3786](https://github.com/axios/axios/pull/3786))
22
- - Don't rely on strict mode behaviour for arguments ([#3470](https://github.com/axios/axios/pull/3470))
47
+ - Don't rely on strict mode behavior for arguments ([#3470](https://github.com/axios/axios/pull/3470))
23
48
  - Adding error handling when missing url ([#3791](https://github.com/axios/axios/pull/3791))
24
49
  - Update isAbsoluteURL.js removing escaping of non-special characters ([#3809](https://github.com/axios/axios/pull/3809))
25
50
  - Use native Array.isArray() in utils.js ([#3836](https://github.com/axios/axios/pull/3836))
@@ -36,14 +61,13 @@ Fixes and Functionality:
36
61
  - Adding responseEncoding prop type in AxiosRequestConfig ([#3918](https://github.com/axios/axios/pull/3918))
37
62
 
38
63
  Internal and Tests:
39
- - Adding axios-test-instance to ecosystem ([#3786](https://github.com/axios/axios/pull/3786))
64
+ - Adding axios-test-instance to ecosystem ([#3496](https://github.com/axios/axios/pull/3496))
40
65
  - Optimize the logic of isAxiosError ([#3546](https://github.com/axios/axios/pull/3546))
41
66
  - Add tests and documentation to display how multiple inceptors work ([#3564](https://github.com/axios/axios/pull/3564))
42
67
  - Updating follow-redirects to version 1.14.7 ([#4379](https://github.com/axios/axios/pull/4379))
43
68
 
44
-
45
69
  Documentation:
46
- - Fixing changelog to show corrext pull request ([#4219](https://github.com/axios/axios/pull/4219))
70
+ - Fixing changelog to show correct pull request ([#4219](https://github.com/axios/axios/pull/4219))
47
71
  - Update upgrade guide for https proxy setting ([#3604](https://github.com/axios/axios/pull/3604))
48
72
 
49
73
  Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
@@ -134,7 +158,7 @@ Huge thanks to everyone who contributed to this release via code (authors listed
134
158
  ### 0.21.4 (September 6, 2021)
135
159
 
136
160
  Fixes and Functionality:
137
- - Fixing JSON transform when data is stringified. Providing backward compatability and complying to the JSON RFC standard ([#4020](https://github.com/axios/axios/pull/4020))
161
+ - Fixing JSON transform when data is stringified. Providing backward compatibility and complying to the JSON RFC standard ([#4020](https://github.com/axios/axios/pull/4020))
138
162
 
139
163
  Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
140
164
 
@@ -169,9 +193,9 @@ Fixes and Functionality:
169
193
 
170
194
  Internal and Tests:
171
195
 
172
- - Updating build dev dependancies ([#3401](https://github.com/axios/axios/pull/3401))
196
+ - Updating build dev dependencies ([#3401](https://github.com/axios/axios/pull/3401))
173
197
  - Fixing builds running on Travis CI ([#3538](https://github.com/axios/axios/pull/3538))
174
- - Updating follow rediect version ([#3694](https://github.com/axios/axios/pull/3694), [#3771](https://github.com/axios/axios/pull/3771))
198
+ - Updating follow redirect version ([#3694](https://github.com/axios/axios/pull/3694), [#3771](https://github.com/axios/axios/pull/3771))
175
199
  - Updating karma sauce launcher to fix failing sauce tests ([#3712](https://github.com/axios/axios/pull/3712), [#3717](https://github.com/axios/axios/pull/3717))
176
200
  - Updating content-type header for application/json to not contain charset field, according do RFC 8259 ([#2154](https://github.com/axios/axios/pull/2154))
177
201
  - Fixing tests by bumping karma-sauce-launcher version ([#3813](https://github.com/axios/axios/pull/3813))
@@ -181,9 +205,9 @@ Documentation:
181
205
 
182
206
  - Updating documentation around the use of `AUTH_TOKEN` with multiple domain endpoints ([#3539](https://github.com/axios/axios/pull/3539))
183
207
  - Remove duplication of item in changelog ([#3523](https://github.com/axios/axios/pull/3523))
184
- - Fixing gramatical errors ([#2642](https://github.com/axios/axios/pull/2642))
208
+ - Fixing grammatical errors ([#2642](https://github.com/axios/axios/pull/2642))
185
209
  - Fixing spelling error ([#3567](https://github.com/axios/axios/pull/3567))
186
- - Moving gitpod metion ([#2637](https://github.com/axios/axios/pull/2637))
210
+ - Moving gitpod mention ([#2637](https://github.com/axios/axios/pull/2637))
187
211
  - Adding new axios documentation website link ([#3681](https://github.com/axios/axios/pull/3681), [#3707](https://github.com/axios/axios/pull/3707))
188
212
  - Updating documentation around dispatching requests ([#3772](https://github.com/axios/axios/pull/3772))
189
213
  - Adding documentation for the type guard isAxiosError ([#3767](https://github.com/axios/axios/pull/3767))
@@ -261,7 +285,7 @@ Internal and Tests:
261
285
 
262
286
  Documentation:
263
287
 
264
- - Fixing simple typo, existant -> existent ([#3252](https://github.com/axios/axios/pull/3252))
288
+ - Fixing simple typo, existent -> existent ([#3252](https://github.com/axios/axios/pull/3252))
265
289
  - Fixing typos ([#3309](https://github.com/axios/axios/pull/3309))
266
290
 
267
291
  Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
package/README.md CHANGED
@@ -23,7 +23,7 @@ Promise based HTTP client for the browser and node.js
23
23
  - [Example](#example)
24
24
  - [Axios API](#axios-api)
25
25
  - [Request method aliases](#request-method-aliases)
26
- - [Concurrency (Deprecated)](#concurrency-deprecated)
26
+ - [Concurrency 👎](#concurrency-deprecated)
27
27
  - [Creating an instance](#creating-an-instance)
28
28
  - [Instance methods](#instance-methods)
29
29
  - [Request Config](#request-config)
@@ -36,11 +36,15 @@ Promise based HTTP client for the browser and node.js
36
36
  - [Multiple Interceptors](#multiple-interceptors)
37
37
  - [Handling Errors](#handling-errors)
38
38
  - [Cancellation](#cancellation)
39
+ - [AbortController](#abortcontroller)
40
+ - [CancelToken 👎](#canceltoken-deprecated)
39
41
  - [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
40
42
  - [Browser](#browser)
41
43
  - [Node.js](#nodejs)
42
44
  - [Query string](#query-string)
43
45
  - [Form data](#form-data)
46
+ - [Automatic serialization](#-automatic-serialization)
47
+ - [Manual FormData passing](#manual-formdata-passing)
44
48
  - [Semver](#semver)
45
49
  - [Promises](#promises)
46
50
  - [TypeScript](#typescript)
@@ -113,7 +117,7 @@ const axios = require('axios').default;
113
117
  Performing a `GET` request
114
118
 
115
119
  ```js
116
- const axios = require('axios');
120
+ const axios = require('axios').default;
117
121
 
118
122
  // Make a request for a user with a given ID
119
123
  axios.get('/user?ID=12345')
@@ -231,7 +235,7 @@ axios('/user/12345');
231
235
 
232
236
  ### Request method aliases
233
237
 
234
- For convenience aliases have been provided for all supported request methods.
238
+ For convenience, aliases have been provided for all common request methods.
235
239
 
236
240
  ##### axios.request(config)
237
241
  ##### axios.get(url[, config])
@@ -414,7 +418,18 @@ These are the available config options for making requests. Only the `url` is re
414
418
 
415
419
  // `maxRedirects` defines the maximum number of redirects to follow in node.js.
416
420
  // If set to 0, no redirects will be followed.
417
- maxRedirects: 5, // default
421
+ maxRedirects: 21, // default
422
+
423
+ // `beforeRedirect` defines a function that will be called before redirect.
424
+ // Use this to adjust the request options upon redirecting,
425
+ // to inspect the latest response headers,
426
+ // or to cancel the request by throwing an error
427
+ // If maxRedirects is set to 0, `beforeRedirect` is not used.
428
+ beforeRedirect: (options, { headers }) => {
429
+ if (options.hostname === "example.com") {
430
+ options.auth = "user:password";
431
+ }
432
+ };
418
433
 
419
434
  // `socketPath` defines a UNIX Socket to be used in node.js.
420
435
  // e.g. '/var/run/docker.sock' to send requests to the docker daemon.
@@ -483,6 +498,11 @@ These are the available config options for making requests. Only the `url` is re
483
498
 
484
499
  // throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
485
500
  clarifyTimeoutError: false,
501
+ },
502
+
503
+ env: {
504
+ // The FormData class to be used to automatically serialize the payload into a FormData object
505
+ FormData: window?.FormData || global?.FormData
486
506
  }
487
507
  }
488
508
  ```
@@ -707,10 +727,30 @@ axios.get('/user/12345')
707
727
 
708
728
  ## Cancellation
709
729
 
710
- You can cancel a request using a *cancel token*.
730
+ ### AbortController
731
+
732
+ Starting from `v0.22.0` Axios supports AbortController to cancel requests in fetch API way:
733
+
734
+ ```js
735
+ const controller = new AbortController();
736
+
737
+ axios.get('/foo/bar', {
738
+ signal: controller.signal
739
+ }).then(function(response) {
740
+ //...
741
+ });
742
+ // cancel the request
743
+ controller.abort()
744
+ ```
745
+
746
+ ### CancelToken `👎deprecated`
747
+
748
+ You can also cancel a request using a *CancelToken*.
711
749
 
712
750
  > The axios cancel token API is based on the withdrawn [cancelable promises proposal](https://github.com/tc39/proposal-cancelable-promises).
713
751
 
752
+ > This API is deprecated since v0.22.0 and shouldn't be used in new projects
753
+
714
754
  You can create a cancel token using the `CancelToken.source` factory as shown below:
715
755
 
716
756
  ```js
@@ -754,22 +794,11 @@ axios.get('/user/12345', {
754
794
  cancel();
755
795
  ```
756
796
 
757
- Axios supports AbortController to abort requests in [`fetch API`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#aborting_a_fetch) way:
758
- ```js
759
- const controller = new AbortController();
760
-
761
- axios.get('/foo/bar', {
762
- signal: controller.signal
763
- }).then(function(response) {
764
- //...
765
- });
766
- // cancel the request
767
- controller.abort()
768
- ```
769
-
770
797
  > Note: you can cancel several requests with the same cancel token/abort controller.
771
798
  > If a cancellation token is already cancelled at the moment of starting an Axios request, then the request is cancelled immediately, without any attempts to make real request.
772
799
 
800
+ > During the transition period, you can use both cancellation APIs, even for the same request:
801
+
773
802
  ## Using application/x-www-form-urlencoded format
774
803
 
775
804
  By default, axios serializes JavaScript objects to `JSON`. To send data in the `application/x-www-form-urlencoded` format instead, you can use one of the following options.
@@ -829,11 +858,75 @@ axios.post('http://something.com/', params.toString());
829
858
 
830
859
  You can also use the [`qs`](https://github.com/ljharb/qs) library.
831
860
 
832
- ###### NOTE
833
- 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).
861
+ > NOTE:
862
+ > The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has [known issues](https://github.com/nodejs/node-v0.x-archive/issues/1665) with that use case.
834
863
 
835
864
  #### Form data
836
865
 
866
+ ##### 🆕 Automatic serialization
867
+
868
+ Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
869
+ header is set to `multipart/form-data`.
870
+
871
+ The following request will submit the data in a FormData format (Browser & Node.js):
872
+
873
+ ```js
874
+ import axios from 'axios';
875
+
876
+ axios.post('https://httpbin.org/post', {x: 1}, {
877
+ headers: {
878
+ 'Content-Type': 'multipart/form-data'
879
+ }
880
+ }).then(({data})=> console.log(data));
881
+ ```
882
+
883
+ In the `node.js` build, the ([`form-data`](https://github.com/form-data/form-data)) polyfill is used by default.
884
+
885
+ You can overload the FormData class by setting the `env.FormData` config variable,
886
+ but you probably won't need it in most cases:
887
+
888
+ ```js
889
+ const axios= require('axios');
890
+ var FormData = require('form-data');
891
+
892
+ axios.post('https://httpbin.org/post', {x: 1, buf: new Buffer(10)}, {
893
+ headers: {
894
+ 'Content-Type': 'multipart/form-data'
895
+ }
896
+ }).then(({data})=> console.log(data));
897
+ ```
898
+
899
+ Axios FormData serializer supports some special endings to perform the following operations:
900
+
901
+ - `{}` - serialize the value with JSON.stringify
902
+ - `[]` - unwrap the array like object as separate fields with the same key
903
+
904
+ ```js
905
+ const axios= require('axios');
906
+
907
+ axios.post('https://httpbin.org/post', {
908
+ 'myObj{}': {x: 1, s: "foo"},
909
+ 'files[]': document.querySelector('#fileInput').files
910
+ }, {
911
+ headers: {
912
+ 'Content-Type': 'multipart/form-data'
913
+ }
914
+ }).then(({data})=> console.log(data));
915
+ ```
916
+
917
+ Axios supports the following shortcut methods: `postForm`, `putForm`, `patchForm`
918
+ which are just the corresponding http methods with a header preset: `Content-Type`: `multipart/form-data`.
919
+
920
+ FileList object can be passed directly:
921
+
922
+ ```js
923
+ await axios.postForm('https://httpbin.org/post', document.querySelector('#fileInput').files)
924
+ ```
925
+
926
+ All files will be sent with the same field names: `files[]`;
927
+
928
+ ##### Manual FormData passing
929
+
837
930
  In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
838
931
 
839
932
  ```js
@@ -844,18 +937,7 @@ form.append('my_field', 'my value');
844
937
  form.append('my_buffer', new Buffer(10));
845
938
  form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
846
939
 
847
- axios.post('https://example.com', form, { headers: form.getHeaders() })
848
- ```
849
-
850
- Alternatively, use an interceptor:
851
-
852
- ```js
853
- axios.interceptors.request.use(config => {
854
- if (config.data instanceof FormData) {
855
- Object.assign(config.headers, config.data.getHeaders());
856
- }
857
- return config;
858
- });
940
+ axios.post('https://example.com', form)
859
941
  ```
860
942
 
861
943
  ## Semver