axios 0.25.0 → 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 +49 -10
- package/README.md +115 -32
- package/dist/axios.js +1876 -173
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +3 -3
- package/dist/axios.min.map +1 -1
- package/index.d.ts +37 -4
- package/lib/adapters/http.js +56 -22
- package/lib/adapters/xhr.js +23 -13
- package/lib/axios.js +8 -1
- package/lib/cancel/CancelToken.js +3 -3
- package/lib/cancel/CanceledError.js +22 -0
- package/lib/core/Axios.js +20 -15
- package/lib/core/AxiosError.js +86 -0
- package/lib/core/dispatchRequest.js +3 -3
- package/lib/core/mergeConfig.js +1 -0
- package/lib/core/settle.js +3 -3
- package/lib/core/transformData.js +1 -1
- package/lib/defaults/env/FormData.js +2 -0
- package/lib/{defaults.js → defaults/index.js} +24 -12
- package/lib/defaults/transitional.js +7 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/null.js +2 -0
- package/lib/helpers/toFormData.js +63 -46
- package/lib/helpers/validator.js +8 -4
- package/lib/utils.js +166 -27
- package/package.json +26 -22
- package/lib/cancel/Cancel.js +0 -19
- package/lib/core/createError.js +0 -18
- package/lib/core/enhanceError.js +0 -43
package/CHANGELOG.md
CHANGED
@@ -1,10 +1,50 @@
|
|
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
|
+
|
28
|
+
### 0.26.1 (March 9, 2022)
|
29
|
+
|
30
|
+
Fixes and Functionality:
|
31
|
+
- Refactored project file structure to avoid circular imports ([#4220](https://github.com/axios/axios/pull/4220))
|
32
|
+
|
33
|
+
### 0.26.0 (February 13, 2022)
|
34
|
+
|
35
|
+
Fixes and Functionality:
|
36
|
+
- Fixed The timeoutErrorMessage property in config not work with Node.js ([#3581](https://github.com/axios/axios/pull/3581))
|
37
|
+
- Added errors to be displayed when the query parsing process itself fails ([#3961](https://github.com/axios/axios/pull/3961))
|
38
|
+
- Fix/remove url required ([#4426](https://github.com/axios/axios/pull/4426))
|
39
|
+
- Update follow-redirects dependency due to Vulnerability ([#4462](https://github.com/axios/axios/pull/4462))
|
40
|
+
- Bump karma from 6.3.11 to 6.3.14 ([#4461](https://github.com/axios/axios/pull/4461))
|
41
|
+
- Bump follow-redirects from 1.14.7 to 1.14.8 ([#4473](https://github.com/axios/axios/pull/4473))
|
42
|
+
|
3
43
|
### 0.25.0 (January 18, 2022)
|
4
44
|
|
5
45
|
Breaking changes:
|
6
46
|
- Fixing maxBodyLength enforcement ([#3786](https://github.com/axios/axios/pull/3786))
|
7
|
-
- Don't rely on strict mode
|
47
|
+
- Don't rely on strict mode behavior for arguments ([#3470](https://github.com/axios/axios/pull/3470))
|
8
48
|
- Adding error handling when missing url ([#3791](https://github.com/axios/axios/pull/3791))
|
9
49
|
- Update isAbsoluteURL.js removing escaping of non-special characters ([#3809](https://github.com/axios/axios/pull/3809))
|
10
50
|
- Use native Array.isArray() in utils.js ([#3836](https://github.com/axios/axios/pull/3836))
|
@@ -21,14 +61,13 @@ Fixes and Functionality:
|
|
21
61
|
- Adding responseEncoding prop type in AxiosRequestConfig ([#3918](https://github.com/axios/axios/pull/3918))
|
22
62
|
|
23
63
|
Internal and Tests:
|
24
|
-
- Adding axios-test-instance to ecosystem ([#
|
64
|
+
- Adding axios-test-instance to ecosystem ([#3496](https://github.com/axios/axios/pull/3496))
|
25
65
|
- Optimize the logic of isAxiosError ([#3546](https://github.com/axios/axios/pull/3546))
|
26
66
|
- Add tests and documentation to display how multiple inceptors work ([#3564](https://github.com/axios/axios/pull/3564))
|
27
67
|
- Updating follow-redirects to version 1.14.7 ([#4379](https://github.com/axios/axios/pull/4379))
|
28
68
|
|
29
|
-
|
30
69
|
Documentation:
|
31
|
-
- Fixing changelog to show
|
70
|
+
- Fixing changelog to show correct pull request ([#4219](https://github.com/axios/axios/pull/4219))
|
32
71
|
- Update upgrade guide for https proxy setting ([#3604](https://github.com/axios/axios/pull/3604))
|
33
72
|
|
34
73
|
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
@@ -119,7 +158,7 @@ Huge thanks to everyone who contributed to this release via code (authors listed
|
|
119
158
|
### 0.21.4 (September 6, 2021)
|
120
159
|
|
121
160
|
Fixes and Functionality:
|
122
|
-
- Fixing JSON transform when data is stringified. Providing backward
|
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))
|
123
162
|
|
124
163
|
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
125
164
|
|
@@ -154,9 +193,9 @@ Fixes and Functionality:
|
|
154
193
|
|
155
194
|
Internal and Tests:
|
156
195
|
|
157
|
-
- Updating build dev
|
196
|
+
- Updating build dev dependencies ([#3401](https://github.com/axios/axios/pull/3401))
|
158
197
|
- Fixing builds running on Travis CI ([#3538](https://github.com/axios/axios/pull/3538))
|
159
|
-
- Updating follow
|
198
|
+
- Updating follow redirect version ([#3694](https://github.com/axios/axios/pull/3694), [#3771](https://github.com/axios/axios/pull/3771))
|
160
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))
|
161
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))
|
162
201
|
- Fixing tests by bumping karma-sauce-launcher version ([#3813](https://github.com/axios/axios/pull/3813))
|
@@ -166,9 +205,9 @@ Documentation:
|
|
166
205
|
|
167
206
|
- Updating documentation around the use of `AUTH_TOKEN` with multiple domain endpoints ([#3539](https://github.com/axios/axios/pull/3539))
|
168
207
|
- Remove duplication of item in changelog ([#3523](https://github.com/axios/axios/pull/3523))
|
169
|
-
- Fixing
|
208
|
+
- Fixing grammatical errors ([#2642](https://github.com/axios/axios/pull/2642))
|
170
209
|
- Fixing spelling error ([#3567](https://github.com/axios/axios/pull/3567))
|
171
|
-
- Moving gitpod
|
210
|
+
- Moving gitpod mention ([#2637](https://github.com/axios/axios/pull/2637))
|
172
211
|
- Adding new axios documentation website link ([#3681](https://github.com/axios/axios/pull/3681), [#3707](https://github.com/axios/axios/pull/3707))
|
173
212
|
- Updating documentation around dispatching requests ([#3772](https://github.com/axios/axios/pull/3772))
|
174
213
|
- Adding documentation for the type guard isAxiosError ([#3767](https://github.com/axios/axios/pull/3767))
|
@@ -246,7 +285,7 @@ Internal and Tests:
|
|
246
285
|
|
247
286
|
Documentation:
|
248
287
|
|
249
|
-
- Fixing simple typo,
|
288
|
+
- Fixing simple typo, existent -> existent ([#3252](https://github.com/axios/axios/pull/3252))
|
250
289
|
- Fixing typos ([#3309](https://github.com/axios/axios/pull/3309))
|
251
290
|
|
252
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
@@ -9,6 +9,7 @@
|
|
9
9
|
[](http://npm-stat.com/charts.html?package=axios)
|
10
10
|
[](https://gitter.im/mzabriskie/axios)
|
11
11
|
[](https://www.codetriage.com/axios/axios)
|
12
|
+
[](https://snyk.io/test/npm/axios)
|
12
13
|
|
13
14
|
Promise based HTTP client for the browser and node.js
|
14
15
|
|
@@ -22,7 +23,7 @@ Promise based HTTP client for the browser and node.js
|
|
22
23
|
- [Example](#example)
|
23
24
|
- [Axios API](#axios-api)
|
24
25
|
- [Request method aliases](#request-method-aliases)
|
25
|
-
- [Concurrency
|
26
|
+
- [Concurrency 👎](#concurrency-deprecated)
|
26
27
|
- [Creating an instance](#creating-an-instance)
|
27
28
|
- [Instance methods](#instance-methods)
|
28
29
|
- [Request Config](#request-config)
|
@@ -35,11 +36,15 @@ Promise based HTTP client for the browser and node.js
|
|
35
36
|
- [Multiple Interceptors](#multiple-interceptors)
|
36
37
|
- [Handling Errors](#handling-errors)
|
37
38
|
- [Cancellation](#cancellation)
|
39
|
+
- [AbortController](#abortcontroller)
|
40
|
+
- [CancelToken 👎](#canceltoken-deprecated)
|
38
41
|
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
|
39
42
|
- [Browser](#browser)
|
40
43
|
- [Node.js](#nodejs)
|
41
44
|
- [Query string](#query-string)
|
42
45
|
- [Form data](#form-data)
|
46
|
+
- [Automatic serialization](#-automatic-serialization)
|
47
|
+
- [Manual FormData passing](#manual-formdata-passing)
|
43
48
|
- [Semver](#semver)
|
44
49
|
- [Promises](#promises)
|
45
50
|
- [TypeScript](#typescript)
|
@@ -112,7 +117,7 @@ const axios = require('axios').default;
|
|
112
117
|
Performing a `GET` request
|
113
118
|
|
114
119
|
```js
|
115
|
-
const axios = require('axios');
|
120
|
+
const axios = require('axios').default;
|
116
121
|
|
117
122
|
// Make a request for a user with a given ID
|
118
123
|
axios.get('/user?ID=12345')
|
@@ -230,7 +235,7 @@ axios('/user/12345');
|
|
230
235
|
|
231
236
|
### Request method aliases
|
232
237
|
|
233
|
-
For convenience aliases have been provided for all
|
238
|
+
For convenience, aliases have been provided for all common request methods.
|
234
239
|
|
235
240
|
##### axios.request(config)
|
236
241
|
##### axios.get(url[, config])
|
@@ -413,7 +418,18 @@ These are the available config options for making requests. Only the `url` is re
|
|
413
418
|
|
414
419
|
// `maxRedirects` defines the maximum number of redirects to follow in node.js.
|
415
420
|
// If set to 0, no redirects will be followed.
|
416
|
-
maxRedirects:
|
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
|
+
};
|
417
433
|
|
418
434
|
// `socketPath` defines a UNIX Socket to be used in node.js.
|
419
435
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
|
@@ -482,6 +498,11 @@ These are the available config options for making requests. Only the `url` is re
|
|
482
498
|
|
483
499
|
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
484
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
|
485
506
|
}
|
486
507
|
}
|
487
508
|
```
|
@@ -706,10 +727,30 @@ axios.get('/user/12345')
|
|
706
727
|
|
707
728
|
## Cancellation
|
708
729
|
|
709
|
-
|
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*.
|
710
749
|
|
711
750
|
> The axios cancel token API is based on the withdrawn [cancelable promises proposal](https://github.com/tc39/proposal-cancelable-promises).
|
712
751
|
|
752
|
+
> This API is deprecated since v0.22.0 and shouldn't be used in new projects
|
753
|
+
|
713
754
|
You can create a cancel token using the `CancelToken.source` factory as shown below:
|
714
755
|
|
715
756
|
```js
|
@@ -753,22 +794,11 @@ axios.get('/user/12345', {
|
|
753
794
|
cancel();
|
754
795
|
```
|
755
796
|
|
756
|
-
Axios supports AbortController to abort requests in [`fetch API`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#aborting_a_fetch) way:
|
757
|
-
```js
|
758
|
-
const controller = new AbortController();
|
759
|
-
|
760
|
-
axios.get('/foo/bar', {
|
761
|
-
signal: controller.signal
|
762
|
-
}).then(function(response) {
|
763
|
-
//...
|
764
|
-
});
|
765
|
-
// cancel the request
|
766
|
-
controller.abort()
|
767
|
-
```
|
768
|
-
|
769
797
|
> Note: you can cancel several requests with the same cancel token/abort controller.
|
770
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.
|
771
799
|
|
800
|
+
> During the transition period, you can use both cancellation APIs, even for the same request:
|
801
|
+
|
772
802
|
## Using application/x-www-form-urlencoded format
|
773
803
|
|
774
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.
|
@@ -828,11 +858,75 @@ axios.post('http://something.com/', params.toString());
|
|
828
858
|
|
829
859
|
You can also use the [`qs`](https://github.com/ljharb/qs) library.
|
830
860
|
|
831
|
-
|
832
|
-
The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has known issues
|
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.
|
833
863
|
|
834
864
|
#### Form data
|
835
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
|
+
|
836
930
|
In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
|
837
931
|
|
838
932
|
```js
|
@@ -843,18 +937,7 @@ form.append('my_field', 'my value');
|
|
843
937
|
form.append('my_buffer', new Buffer(10));
|
844
938
|
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
845
939
|
|
846
|
-
axios.post('https://example.com', form
|
847
|
-
```
|
848
|
-
|
849
|
-
Alternatively, use an interceptor:
|
850
|
-
|
851
|
-
```js
|
852
|
-
axios.interceptors.request.use(config => {
|
853
|
-
if (config.data instanceof FormData) {
|
854
|
-
Object.assign(config.headers, config.data.getHeaders());
|
855
|
-
}
|
856
|
-
return config;
|
857
|
-
});
|
940
|
+
axios.post('https://example.com', form)
|
858
941
|
```
|
859
942
|
|
860
943
|
## Semver
|