@wopee-io/wopee.wdio 4.7.0 → 5.0.2
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/build/adapter/fullPageScreenshotAdapter/fullPageScreenshotAdapter.d.ts +2 -2
- package/build/adapter/fullPageScreenshotAdapter/fullPageScreenshotAdapter.d.ts.map +1 -1
- package/build/adapter/fullPageScreenshotAdapter/fullPageScreenshotAdapter.js +18 -20
- package/build/adapter/fullPageScreenshotAdapter/fullPageScreenshotAdapter.js.map +1 -1
- package/build/desktopBrowser/commands/trackElement.js +2 -2
- package/build/desktopBrowser/commands/trackElement.js.map +1 -1
- package/build/desktopBrowser/commands/trackScreen.js +2 -2
- package/build/desktopBrowser/commands/trackScreen.js.map +1 -1
- package/build/desktopBrowser/methods/images.d.ts +1 -1
- package/build/desktopBrowser/methods/images.d.ts.map +1 -1
- package/build/desktopBrowser/methods/images.interfaces.d.ts +2 -2
- package/build/desktopBrowser/methods/images.interfaces.d.ts.map +1 -1
- package/build/desktopBrowser/methods/images.interfaces.js.map +1 -1
- package/build/desktopBrowser/methods/images.js +5 -5
- package/build/desktopBrowser/methods/images.js.map +1 -1
- package/build/domain/model/config.interface.d.ts +82 -13
- package/build/domain/model/config.interface.d.ts.map +1 -1
- package/build/domain/model/config.interface.js +16 -1
- package/build/domain/model/config.interface.js.map +1 -1
- package/build/domain/model/service.interface.d.ts +3 -3
- package/build/domain/model/service.interface.d.ts.map +1 -1
- package/build/domain/model/service.interface.js.map +1 -1
- package/build/domain/service/configurationService.d.ts +5 -0
- package/build/domain/service/configurationService.d.ts.map +1 -0
- package/build/domain/service/configurationService.js +65 -0
- package/build/domain/service/configurationService.js.map +1 -0
- package/build/domain/service/wopeeService.d.ts.map +1 -1
- package/build/domain/service/wopeeService.js +2 -2
- package/build/domain/service/wopeeService.js.map +1 -1
- package/build/utils/versionMetadata.js +2 -2
- package/docs/configuration.md +9 -18
- package/node_modules/@autonomous-testing/sdk/.github/workflows/ci_cd.yaml +3 -1
- package/node_modules/@autonomous-testing/sdk/build/core/domain/entities/createIntegrationStepPayload.interface.d.ts +6 -0
- package/node_modules/@autonomous-testing/sdk/build/core/domain/entities/createIntegrationStepPayload.interface.js +2 -0
- package/node_modules/@autonomous-testing/sdk/build/core/domain/entities/index.d.ts +9 -13
- package/node_modules/@autonomous-testing/sdk/build/core/domain/entities/index.js +5 -1
- package/node_modules/@autonomous-testing/sdk/build/core/domain/entities/visualAssert.interface.d.ts +22 -0
- package/node_modules/@autonomous-testing/sdk/build/core/domain/entities/visualAssert.interface.js +18 -0
- package/node_modules/@autonomous-testing/sdk/build/core/domain/entities/visualAssertPayload.interface.d.ts +17 -0
- package/node_modules/@autonomous-testing/sdk/build/core/domain/entities/visualAssertPayload.interface.js +11 -0
- package/node_modules/@autonomous-testing/sdk/build/core/ports/api.d.ts +2 -1
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/adapter.d.ts +2 -1
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/adapter.js +10 -0
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/factories.d.ts +5 -3
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/factories.js +23 -0
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/interface.d.ts +63 -4
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/interface.js +21 -2
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/mutations.d.ts +1 -0
- package/node_modules/@autonomous-testing/sdk/build/infrastructure/adapters/apolloAdapter/mutations.js +8 -1
- package/node_modules/@autonomous-testing/sdk/build/shared/metadata/versionMetadata.js +2 -2
- package/node_modules/@autonomous-testing/sdk/package.json +7 -5
- package/node_modules/axios/CHANGELOG.md +157 -61
- package/node_modules/axios/README.md +271 -80
- package/node_modules/axios/SECURITY.md +3 -3
- package/node_modules/axios/UPGRADE_GUIDE.md +37 -15
- package/node_modules/axios/bin/check-build-version.js +19 -0
- package/node_modules/axios/bin/ssl_hotfix.js +22 -0
- package/node_modules/axios/dist/axios.js +2014 -2222
- package/node_modules/axios/dist/axios.js.map +1 -0
- package/node_modules/axios/dist/axios.min.js +2 -3
- package/node_modules/axios/dist/axios.min.js.map +1 -0
- package/node_modules/axios/dist/esm/axios.js +2379 -0
- package/node_modules/axios/dist/esm/axios.js.map +1 -0
- package/node_modules/axios/dist/esm/axios.min.js +2 -0
- package/node_modules/axios/dist/esm/axios.min.js.map +1 -0
- package/node_modules/axios/index.d.ts +106 -19
- package/node_modules/axios/lib/adapters/http.js +155 -116
- package/node_modules/axios/lib/adapters/xhr.js +15 -11
- package/node_modules/axios/lib/axios.js +5 -1
- package/node_modules/axios/lib/cancel/CancelToken.js +4 -5
- package/node_modules/axios/lib/cancel/CanceledError.js +4 -2
- package/node_modules/axios/lib/core/Axios.js +18 -2
- package/node_modules/axios/lib/core/AxiosError.js +12 -1
- package/node_modules/axios/lib/core/InterceptorManager.js +9 -0
- package/node_modules/axios/lib/core/buildFullPath.js +5 -2
- package/node_modules/axios/lib/core/dispatchRequest.js +7 -0
- package/node_modules/axios/lib/core/mergeConfig.js +3 -0
- package/node_modules/axios/lib/core/transformData.js +3 -2
- package/node_modules/axios/lib/defaults/index.js +42 -13
- package/node_modules/axios/lib/env/data.js +1 -1
- package/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +42 -0
- package/node_modules/axios/lib/helpers/bind.js +1 -5
- package/node_modules/axios/lib/helpers/buildURL.js +18 -33
- package/node_modules/axios/lib/helpers/combineURLs.js +1 -1
- package/node_modules/axios/lib/helpers/formDataToJSON.js +74 -0
- package/node_modules/axios/lib/helpers/fromDataURI.js +51 -0
- package/node_modules/axios/lib/helpers/isURLSameOrigin.js +12 -12
- package/node_modules/axios/lib/helpers/parseHeaders.js +2 -2
- package/node_modules/axios/lib/helpers/toFormData.js +141 -34
- package/node_modules/axios/lib/helpers/toURLEncodedForm.js +18 -0
- package/node_modules/axios/lib/platform/browser/classes/FormData.js +3 -0
- package/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js +5 -0
- package/node_modules/axios/lib/platform/browser/index.js +11 -0
- package/node_modules/axios/lib/platform/index.js +3 -0
- package/node_modules/axios/lib/platform/node/classes/FormData.js +3 -0
- package/node_modules/axios/lib/platform/node/classes/URLSearchParams.js +5 -0
- package/node_modules/axios/lib/platform/node/index.js +11 -0
- package/node_modules/axios/lib/utils.js +68 -16
- package/node_modules/axios/package.json +20 -7
- package/node_modules/axios/rollup.config.js +60 -0
- package/node_modules/proxy-from-env/.eslintrc +29 -0
- package/node_modules/proxy-from-env/.travis.yml +10 -0
- package/node_modules/proxy-from-env/LICENSE +20 -0
- package/node_modules/proxy-from-env/README.md +131 -0
- package/node_modules/proxy-from-env/index.js +108 -0
- package/node_modules/proxy-from-env/package.json +34 -0
- package/node_modules/proxy-from-env/test.js +483 -0
- package/package.json +4 -4
- package/build/adapter/wdioConfigAdapter/wdioConfigAdapter.d.ts +0 -10
- package/build/adapter/wdioConfigAdapter/wdioConfigAdapter.d.ts.map +0 -1
- package/build/adapter/wdioConfigAdapter/wdioConfigAdapter.interface.d.ts +0 -28
- package/build/adapter/wdioConfigAdapter/wdioConfigAdapter.interface.d.ts.map +0 -1
- package/build/adapter/wdioConfigAdapter/wdioConfigAdapter.interface.js +0 -12
- package/build/adapter/wdioConfigAdapter/wdioConfigAdapter.interface.js.map +0 -1
- package/build/adapter/wdioConfigAdapter/wdioConfigAdapter.js +0 -57
- package/build/adapter/wdioConfigAdapter/wdioConfigAdapter.js.map +0 -1
- package/build/domain/model/croppingOptions.interface.d.ts +0 -8
- package/build/domain/model/croppingOptions.interface.d.ts.map +0 -1
- package/build/domain/model/croppingOptions.interface.js +0 -12
- package/build/domain/model/croppingOptions.interface.js.map +0 -1
- package/build/port/driven/configDrivingPort/configDrivingPort.d.ts +0 -9
- package/build/port/driven/configDrivingPort/configDrivingPort.d.ts.map +0 -1
- package/build/port/driven/configDrivingPort/configDrivingPort.js +0 -15
- package/build/port/driven/configDrivingPort/configDrivingPort.js.map +0 -1
- package/build/port/driven/configDrivingPort/configDrivingPortDefaults.d.ts +0 -6
- package/build/port/driven/configDrivingPort/configDrivingPortDefaults.d.ts.map +0 -1
- package/build/port/driven/configDrivingPort/configDrivingPortDefaults.js +0 -36
- package/build/port/driven/configDrivingPort/configDrivingPortDefaults.js.map +0 -1
- package/node_modules/axios/dist/axios.map +0 -1
- package/node_modules/axios/dist/axios.min.map +0 -1
- /package/node_modules/axios/lib/{defaults/env → env/classes}/FormData.js +0 -0
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
[](https://www.npmjs.org/package/axios)
|
|
4
4
|
[](https://cdnjs.com/libraries/axios)
|
|
5
5
|

|
|
6
|
-
[](https://gitpod.io/#https://github.com/axios/axios)
|
|
6
|
+
[](https://gitpod.io/#https://github.com/axios/axios)
|
|
7
7
|
[](https://coveralls.io/r/mzabriskie/axios)
|
|
8
8
|
[](https://packagephobia.now.sh/result?p=axios)
|
|
9
|
-
[](
|
|
9
|
+
[](https://npm-stat.com/charts.html?package=axios)
|
|
10
10
|
[](https://gitter.im/mzabriskie/axios)
|
|
11
11
|
[](https://www.codetriage.com/axios/axios)
|
|
12
12
|
[](https://snyk.io/test/npm/axios)
|
|
13
|
+

|
|
13
14
|
|
|
14
15
|
Promise based HTTP client for the browser and node.js
|
|
15
16
|
|
|
@@ -39,12 +40,14 @@ Promise based HTTP client for the browser and node.js
|
|
|
39
40
|
- [AbortController](#abortcontroller)
|
|
40
41
|
- [CancelToken 👎](#canceltoken-deprecated)
|
|
41
42
|
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
|
|
42
|
-
- [
|
|
43
|
-
- [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
- [URLSearchParams](#urlsearchparams)
|
|
44
|
+
- [Query string](#query-string-older-browsers)
|
|
45
|
+
- [🆕 Automatic serialization](#-automatic-serialization-to-urlsearchparams)
|
|
46
|
+
- [Using multipart/form-data format](#using-multipartform-data-format)
|
|
47
|
+
- [FormData](#formdata)
|
|
48
|
+
- [🆕 Automatic serialization](#-automatic-serialization-to-formdata)
|
|
49
|
+
- [Files Posting](#files-posting)
|
|
50
|
+
- [HTML Form Posting](#html-form-posting-browser)
|
|
48
51
|
- [Semver](#semver)
|
|
49
52
|
- [Promises](#promises)
|
|
50
53
|
- [TypeScript](#typescript)
|
|
@@ -55,17 +58,18 @@ Promise based HTTP client for the browser and node.js
|
|
|
55
58
|
## Features
|
|
56
59
|
|
|
57
60
|
- Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser
|
|
58
|
-
- Make [http](
|
|
61
|
+
- Make [http](https://nodejs.org/api/http.html) requests from node.js
|
|
59
62
|
- Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
|
|
60
63
|
- Intercept request and response
|
|
61
64
|
- Transform request and response data
|
|
62
65
|
- Cancel requests
|
|
63
66
|
- Automatic transforms for JSON data
|
|
64
|
-
-
|
|
67
|
+
- 🆕 Automatic data object serialization to `multipart/form-data` and `x-www-form-urlencoded` body encodings
|
|
68
|
+
- Client side support for protecting against [XSRF](https://en.wikipedia.org/wiki/Cross-site_request_forgery)
|
|
65
69
|
|
|
66
70
|
## Browser Support
|
|
67
71
|
|
|
68
|
-
 |  |  |  |  |  |
|
|
69
73
|
--- | --- | --- | --- | --- | --- |
|
|
70
74
|
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
|
|
71
75
|
|
|
@@ -91,6 +95,12 @@ Using yarn:
|
|
|
91
95
|
$ yarn add axios
|
|
92
96
|
```
|
|
93
97
|
|
|
98
|
+
Using pnpm:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
$ pnpm add axios
|
|
102
|
+
```
|
|
103
|
+
|
|
94
104
|
Using jsDelivr CDN:
|
|
95
105
|
|
|
96
106
|
```html
|
|
@@ -147,7 +157,7 @@ axios.get('/user', {
|
|
|
147
157
|
})
|
|
148
158
|
.then(function () {
|
|
149
159
|
// always executed
|
|
150
|
-
});
|
|
160
|
+
});
|
|
151
161
|
|
|
152
162
|
// Want to use async/await? Add the `async` keyword to your outer function/method.
|
|
153
163
|
async function getUser() {
|
|
@@ -218,7 +228,7 @@ axios({
|
|
|
218
228
|
// GET request for remote image in node.js
|
|
219
229
|
axios({
|
|
220
230
|
method: 'get',
|
|
221
|
-
url: '
|
|
231
|
+
url: 'https://bit.ly/2mTM3nY',
|
|
222
232
|
responseType: 'stream'
|
|
223
233
|
})
|
|
224
234
|
.then(function (response) {
|
|
@@ -330,10 +340,9 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
330
340
|
ID: 12345
|
|
331
341
|
},
|
|
332
342
|
|
|
333
|
-
// `paramsSerializer` is an optional
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return Qs.stringify(params, {arrayFormat: 'brackets'})
|
|
343
|
+
// `paramsSerializer` is an optional config in charge of serializing `params`
|
|
344
|
+
paramsSerializer: {
|
|
345
|
+
indexes: null // array indexes format (null - no brackets, false - empty brackets, true - brackets with indexes)
|
|
337
346
|
},
|
|
338
347
|
|
|
339
348
|
// `data` is the data to be sent as the request body
|
|
@@ -345,7 +354,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
345
354
|
data: {
|
|
346
355
|
firstName: 'Fred'
|
|
347
356
|
},
|
|
348
|
-
|
|
357
|
+
|
|
349
358
|
// syntax alternative to send data into the body
|
|
350
359
|
// method post
|
|
351
360
|
// only the value is sent, not the key
|
|
@@ -390,6 +399,9 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
390
399
|
// `xsrfHeaderName` is the name of the http header that carries the xsrf token value
|
|
391
400
|
xsrfHeaderName: 'X-XSRF-TOKEN', // default
|
|
392
401
|
|
|
402
|
+
// `undefined` (default) - set XSRF header only for the same origin requests
|
|
403
|
+
withXSRFToken: boolean | undefined | ((config: AxiosRequestConfig) => boolean | undefined),
|
|
404
|
+
|
|
393
405
|
// `onUploadProgress` allows handling of progress events for uploads
|
|
394
406
|
// browser only
|
|
395
407
|
onUploadProgress: function (progressEvent) {
|
|
@@ -429,7 +441,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
429
441
|
if (options.hostname === "example.com") {
|
|
430
442
|
options.auth = "user:password";
|
|
431
443
|
}
|
|
432
|
-
}
|
|
444
|
+
},
|
|
433
445
|
|
|
434
446
|
// `socketPath` defines a UNIX Socket to be used in node.js.
|
|
435
447
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
|
|
@@ -453,7 +465,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
453
465
|
// supplies credentials.
|
|
454
466
|
// This will set an `Proxy-Authorization` header, overwriting any existing
|
|
455
467
|
// `Proxy-Authorization` custom headers you have set using `headers`.
|
|
456
|
-
// If the proxy server uses HTTPS, then you must set the protocol to `https`.
|
|
468
|
+
// If the proxy server uses HTTPS, then you must set the protocol to `https`.
|
|
457
469
|
proxy: {
|
|
458
470
|
protocol: 'https',
|
|
459
471
|
host: '127.0.0.1',
|
|
@@ -472,8 +484,8 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
472
484
|
// an alternative way to cancel Axios requests using AbortController
|
|
473
485
|
signal: new AbortController().signal,
|
|
474
486
|
|
|
475
|
-
// `decompress` indicates whether or not the response body should be decompressed
|
|
476
|
-
// automatically. If set to `true` will also remove the 'content-encoding' header
|
|
487
|
+
// `decompress` indicates whether or not the response body should be decompressed
|
|
488
|
+
// automatically. If set to `true` will also remove the 'content-encoding' header
|
|
477
489
|
// from the responses objects of all decompressed responses
|
|
478
490
|
// - Node only (XHR cannot turn off decompression)
|
|
479
491
|
decompress: true // default
|
|
@@ -495,7 +507,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
495
507
|
|
|
496
508
|
// try to parse the response string as JSON even if `responseType` is not 'json'
|
|
497
509
|
forcedJSONParsing: true,
|
|
498
|
-
|
|
510
|
+
|
|
499
511
|
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
|
500
512
|
clarifyTimeoutError: false,
|
|
501
513
|
},
|
|
@@ -503,6 +515,13 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
503
515
|
env: {
|
|
504
516
|
// The FormData class to be used to automatically serialize the payload into a FormData object
|
|
505
517
|
FormData: window?.FormData || global?.FormData
|
|
518
|
+
},
|
|
519
|
+
|
|
520
|
+
formSerializer: {
|
|
521
|
+
visitor: (value, key, path, helpers)=> {}; // custom visitor function to serialize form values
|
|
522
|
+
dots: boolean; // use dots instead of brackets format
|
|
523
|
+
metaTokens: boolean; // keep special endings like {} in parameter key
|
|
524
|
+
indexes: boolean; // array indexes format null - no brackets, false - empty brackets, true - brackets with indexes
|
|
506
525
|
}
|
|
507
526
|
}
|
|
508
527
|
```
|
|
@@ -523,7 +542,7 @@ The response for a request contains the following information.
|
|
|
523
542
|
statusText: 'OK',
|
|
524
543
|
|
|
525
544
|
// `headers` the HTTP headers that the server responded with
|
|
526
|
-
// All header names are
|
|
545
|
+
// All header names are lowercase and can be accessed using the bracket notation.
|
|
527
546
|
// Example: `response.headers['content-type']`
|
|
528
547
|
headers: {},
|
|
529
548
|
|
|
@@ -582,7 +601,7 @@ instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
|
582
601
|
|
|
583
602
|
### Config order of precedence
|
|
584
603
|
|
|
585
|
-
Config will be merged with an order of precedence. The order is library defaults found in [lib/defaults.js](https://github.com/axios/axios/blob/master/lib/defaults.js#L28), 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.
|
|
604
|
+
Config will be merged with an order of precedence. The order is library defaults found in [lib/defaults.js](https://github.com/axios/axios/blob/master/lib/defaults/index.js#L28), 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.
|
|
586
605
|
|
|
587
606
|
```js
|
|
588
607
|
// Create an instance using the config defaults provided by the library
|
|
@@ -632,6 +651,15 @@ const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
|
|
|
632
651
|
axios.interceptors.request.eject(myInterceptor);
|
|
633
652
|
```
|
|
634
653
|
|
|
654
|
+
You can also clear all interceptors for requests or responses.
|
|
655
|
+
```js
|
|
656
|
+
const instance = axios.create();
|
|
657
|
+
instance.interceptors.request.use(function () {/*...*/});
|
|
658
|
+
instance.interceptors.request.clear(); // Removes interceptors from requests
|
|
659
|
+
instance.interceptors.response.use(function () {/*...*/});
|
|
660
|
+
instance.interceptors.response.clear(); // Removes interceptors from responses
|
|
661
|
+
```
|
|
662
|
+
|
|
635
663
|
You can add interceptors to a custom instance of axios.
|
|
636
664
|
|
|
637
665
|
```js
|
|
@@ -640,7 +668,7 @@ instance.interceptors.request.use(function () {/*...*/});
|
|
|
640
668
|
```
|
|
641
669
|
|
|
642
670
|
When you add request interceptors, they are presumed to be asynchronous by default. This can cause a delay
|
|
643
|
-
in the execution of your axios request when the main thread is blocked (a promise is created under the hood for
|
|
671
|
+
in the execution of your axios request when the main thread is blocked (a promise is created under the hood for
|
|
644
672
|
the interceptor and your request gets put on the bottom of the call stack). If your request interceptors are synchronous you can add a flag
|
|
645
673
|
to the options object that will tell axios to run the code synchronously and avoid any delays in request execution.
|
|
646
674
|
|
|
@@ -651,7 +679,7 @@ axios.interceptors.request.use(function (config) {
|
|
|
651
679
|
}, null, { synchronous: true });
|
|
652
680
|
```
|
|
653
681
|
|
|
654
|
-
If you want to execute a particular interceptor based on a runtime check,
|
|
682
|
+
If you want to execute a particular interceptor based on a runtime check,
|
|
655
683
|
you can add a `runWhen` function to the options object. The interceptor will not be executed **if and only if** the return
|
|
656
684
|
of `runWhen` is `false`. The function will be called with the config
|
|
657
685
|
object (don't forget that you can bind your own arguments to it as well.) This can be handy when you have an
|
|
@@ -674,12 +702,12 @@ and when the response was fulfilled
|
|
|
674
702
|
- then each interceptor is executed
|
|
675
703
|
- then they are executed in the order they were added
|
|
676
704
|
- then only the last interceptor's result is returned
|
|
677
|
-
- then every interceptor receives the result of
|
|
705
|
+
- then every interceptor receives the result of its predecessor
|
|
678
706
|
- and when the fulfillment-interceptor throws
|
|
679
707
|
- then the following fulfillment-interceptor is not called
|
|
680
708
|
- then the following rejection-interceptor is called
|
|
681
709
|
- once caught, another following fulfill-interceptor is called again (just like in a promise chain).
|
|
682
|
-
|
|
710
|
+
|
|
683
711
|
Read [the interceptor tests](./test/specs/interceptors.spec.js) for seeing all this in code.
|
|
684
712
|
|
|
685
713
|
## Handling Errors
|
|
@@ -795,26 +823,25 @@ cancel();
|
|
|
795
823
|
```
|
|
796
824
|
|
|
797
825
|
> Note: you can cancel several requests with the same cancel token/abort controller.
|
|
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.
|
|
826
|
+
> 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 a real request.
|
|
799
827
|
|
|
800
828
|
> During the transition period, you can use both cancellation APIs, even for the same request:
|
|
801
829
|
|
|
802
|
-
## Using application/x-www-form-urlencoded format
|
|
830
|
+
## Using `application/x-www-form-urlencoded` format
|
|
803
831
|
|
|
804
|
-
|
|
832
|
+
### URLSearchParams
|
|
805
833
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
In a browser, you can use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API as follows:
|
|
834
|
+
By default, axios serializes JavaScript objects to `JSON`. To send data in the [`application/x-www-form-urlencoded` format](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) instead, you can use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API, which is [supported](http://www.caniuse.com/#feat=urlsearchparams) in the vast majority of browsers, [and Node](https://nodejs.org/api/url.html#url_class_urlsearchparams) starting with v10 (released in 2018).
|
|
809
835
|
|
|
810
836
|
```js
|
|
811
|
-
const params = new URLSearchParams();
|
|
812
|
-
params.append('
|
|
813
|
-
params.append('param2', 'value2');
|
|
837
|
+
const params = new URLSearchParams({ foo: 'bar' });
|
|
838
|
+
params.append('extraparam', 'value');
|
|
814
839
|
axios.post('/foo', params);
|
|
815
840
|
```
|
|
816
841
|
|
|
817
|
-
|
|
842
|
+
### Query string (Older browsers)
|
|
843
|
+
|
|
844
|
+
For compatibility with very old browsers, there is a [polyfill](https://github.com/WebReflection/url-search-params) available (make sure to polyfill the global environment).
|
|
818
845
|
|
|
819
846
|
Alternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library:
|
|
820
847
|
|
|
@@ -837,35 +864,99 @@ const options = {
|
|
|
837
864
|
axios(options);
|
|
838
865
|
```
|
|
839
866
|
|
|
840
|
-
### Node.js
|
|
867
|
+
### Older Node.js versions
|
|
841
868
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
In node.js, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
|
|
869
|
+
For older Node.js engines, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
|
|
845
870
|
|
|
846
871
|
```js
|
|
847
872
|
const querystring = require('querystring');
|
|
848
|
-
axios.post('
|
|
873
|
+
axios.post('https://something.com/', querystring.stringify({ foo: 'bar' }));
|
|
849
874
|
```
|
|
850
875
|
|
|
851
|
-
|
|
876
|
+
You can also use the [`qs`](https://github.com/ljharb/qs) library.
|
|
877
|
+
|
|
878
|
+
> NOTE:
|
|
879
|
+
> 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.
|
|
880
|
+
|
|
881
|
+
### 🆕 Automatic serialization to URLSearchParams
|
|
882
|
+
|
|
883
|
+
Axios will automatically serialize the data object to urlencoded format if the content-type header is set to "application/x-www-form-urlencoded".
|
|
884
|
+
|
|
885
|
+
```
|
|
886
|
+
const data = {
|
|
887
|
+
x: 1,
|
|
888
|
+
arr: [1, 2, 3],
|
|
889
|
+
arr2: [1, [2], 3],
|
|
890
|
+
users: [{name: 'Peter', surname: 'Griffin'}, {name: 'Thomas', surname: 'Anderson'}],
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
await axios.postForm('https://postman-echo.com/post', data,
|
|
894
|
+
{headers: {'content-type': 'application/x-www-form-urlencoded'}}
|
|
895
|
+
);
|
|
896
|
+
```
|
|
897
|
+
|
|
898
|
+
The server will handle it as
|
|
852
899
|
|
|
853
900
|
```js
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
901
|
+
{
|
|
902
|
+
x: '1',
|
|
903
|
+
'arr[]': [ '1', '2', '3' ],
|
|
904
|
+
'arr2[0]': '1',
|
|
905
|
+
'arr2[1][0]': '2',
|
|
906
|
+
'arr2[2]': '3',
|
|
907
|
+
'arr3[]': [ '1', '2', '3' ],
|
|
908
|
+
'users[0][name]': 'Peter',
|
|
909
|
+
'users[0][surname]': 'griffin',
|
|
910
|
+
'users[1][name]': 'Thomas',
|
|
911
|
+
'users[1][surname]': 'Anderson'
|
|
912
|
+
}
|
|
913
|
+
````
|
|
914
|
+
|
|
915
|
+
If your backend body-parser (like `body-parser` of `express.js`) supports nested objects decoding, you will get the same object on the server-side automatically
|
|
916
|
+
|
|
917
|
+
```js
|
|
918
|
+
var app = express();
|
|
919
|
+
|
|
920
|
+
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
|
|
921
|
+
|
|
922
|
+
app.post('/', function (req, res, next) {
|
|
923
|
+
// echo body as JSON
|
|
924
|
+
res.send(JSON.stringify(req.body));
|
|
925
|
+
});
|
|
926
|
+
|
|
927
|
+
server = app.listen(3000);
|
|
857
928
|
```
|
|
858
929
|
|
|
859
|
-
|
|
930
|
+
## Using `multipart/form-data` format
|
|
860
931
|
|
|
861
|
-
|
|
862
|
-
|
|
932
|
+
### FormData
|
|
933
|
+
|
|
934
|
+
To send the data as a `multipart/formdata` you need to pass a formData instance as a payload.
|
|
935
|
+
Setting the `Content-Type` header is not required as Axios guesses it based on the payload type.
|
|
936
|
+
|
|
937
|
+
```js
|
|
938
|
+
const formData = new FormData();
|
|
939
|
+
formData.append('foo', 'bar');
|
|
940
|
+
|
|
941
|
+
axios.post('https://httpbin.org/post', formData);
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
|
|
945
|
+
|
|
946
|
+
```js
|
|
947
|
+
const FormData = require('form-data');
|
|
863
948
|
|
|
864
|
-
|
|
949
|
+
const form = new FormData();
|
|
950
|
+
form.append('my_field', 'my value');
|
|
951
|
+
form.append('my_buffer', new Buffer(10));
|
|
952
|
+
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
|
953
|
+
|
|
954
|
+
axios.post('https://example.com', form)
|
|
955
|
+
```
|
|
865
956
|
|
|
866
|
-
|
|
957
|
+
### 🆕 Automatic serialization to FormData
|
|
867
958
|
|
|
868
|
-
Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
|
|
959
|
+
Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
|
|
869
960
|
header is set to `multipart/form-data`.
|
|
870
961
|
|
|
871
962
|
The following request will submit the data in a FormData format (Browser & Node.js):
|
|
@@ -899,59 +990,159 @@ axios.post('https://httpbin.org/post', {x: 1, buf: new Buffer(10)}, {
|
|
|
899
990
|
Axios FormData serializer supports some special endings to perform the following operations:
|
|
900
991
|
|
|
901
992
|
- `{}` - serialize the value with JSON.stringify
|
|
902
|
-
- `[]` - unwrap the array
|
|
993
|
+
- `[]` - unwrap the array-like object as separate fields with the same key
|
|
994
|
+
|
|
995
|
+
> NOTE:
|
|
996
|
+
> unwrap/expand operation will be used by default on arrays and FileList objects
|
|
997
|
+
|
|
998
|
+
FormData serializer supports additional options via `config.formSerializer: object` property to handle rare cases:
|
|
999
|
+
|
|
1000
|
+
- `visitor: Function` - user-defined visitor function that will be called recursively to serialize the data object
|
|
1001
|
+
to a `FormData` object by following custom rules.
|
|
1002
|
+
|
|
1003
|
+
- `dots: boolean = false` - use dot notation instead of brackets to serialize arrays and objects;
|
|
1004
|
+
|
|
1005
|
+
- `metaTokens: boolean = true` - add the special ending (e.g `user{}: '{"name": "John"}'`) in the FormData key.
|
|
1006
|
+
The back-end body-parser could potentially use this meta-information to automatically parse the value as JSON.
|
|
1007
|
+
|
|
1008
|
+
- `indexes: null|false|true = false` - controls how indexes will be added to unwrapped keys of `flat` array-like objects
|
|
1009
|
+
|
|
1010
|
+
- `null` - don't add brackets (`arr: 1`, `arr: 2`, `arr: 3`)
|
|
1011
|
+
- `false`(default) - add empty brackets (`arr[]: 1`, `arr[]: 2`, `arr[]: 3`)
|
|
1012
|
+
- `true` - add brackets with indexes (`arr[0]: 1`, `arr[1]: 2`, `arr[2]: 3`)
|
|
1013
|
+
|
|
1014
|
+
Let's say we have an object like this one:
|
|
903
1015
|
|
|
904
1016
|
```js
|
|
905
|
-
const
|
|
1017
|
+
const obj = {
|
|
1018
|
+
x: 1,
|
|
1019
|
+
arr: [1, 2, 3],
|
|
1020
|
+
arr2: [1, [2], 3],
|
|
1021
|
+
users: [{name: 'Peter', surname: 'Griffin'}, {name: 'Thomas', surname: 'Anderson'}],
|
|
1022
|
+
'obj2{}': [{x:1}]
|
|
1023
|
+
};
|
|
1024
|
+
```
|
|
906
1025
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1026
|
+
The following steps will be executed by the Axios serializer internally:
|
|
1027
|
+
|
|
1028
|
+
```js
|
|
1029
|
+
const formData= new FormData();
|
|
1030
|
+
formData.append('x', '1');
|
|
1031
|
+
formData.append('arr[]', '1');
|
|
1032
|
+
formData.append('arr[]', '2');
|
|
1033
|
+
formData.append('arr[]', '3');
|
|
1034
|
+
formData.append('arr2[0]', '1');
|
|
1035
|
+
formData.append('arr2[1][0]', '2');
|
|
1036
|
+
formData.append('arr2[2]', '3');
|
|
1037
|
+
formData.append('users[0][name]', 'Peter');
|
|
1038
|
+
formData.append('users[0][surname]', 'Griffin');
|
|
1039
|
+
formData.append('users[1][name]', 'Thomas');
|
|
1040
|
+
formData.append('users[1][surname]', 'Anderson');
|
|
1041
|
+
formData.append('obj2{}', '[{"x":1}]');
|
|
915
1042
|
```
|
|
916
1043
|
|
|
917
1044
|
Axios supports the following shortcut methods: `postForm`, `putForm`, `patchForm`
|
|
918
|
-
which are just the corresponding http methods with
|
|
1045
|
+
which are just the corresponding http methods with the `Content-Type` header preset to `multipart/form-data`.
|
|
1046
|
+
|
|
1047
|
+
## Files Posting
|
|
1048
|
+
|
|
1049
|
+
You can easily sumbit a single file
|
|
1050
|
+
|
|
1051
|
+
```js
|
|
1052
|
+
await axios.postForm('https://httpbin.org/post', {
|
|
1053
|
+
'myVar' : 'foo',
|
|
1054
|
+
'file': document.querySelector('#fileInput').files[0]
|
|
1055
|
+
});
|
|
1056
|
+
```
|
|
919
1057
|
|
|
920
|
-
|
|
1058
|
+
or multiple files as `multipart/form-data`.
|
|
1059
|
+
|
|
1060
|
+
```js
|
|
1061
|
+
await axios.postForm('https://httpbin.org/post', {
|
|
1062
|
+
'files[]': document.querySelector('#fileInput').files
|
|
1063
|
+
});
|
|
1064
|
+
```
|
|
1065
|
+
|
|
1066
|
+
`FileList` object can be passed directly:
|
|
921
1067
|
|
|
922
1068
|
```js
|
|
923
1069
|
await axios.postForm('https://httpbin.org/post', document.querySelector('#fileInput').files)
|
|
924
1070
|
```
|
|
925
1071
|
|
|
926
|
-
All files will be sent with the same field names: `files[]
|
|
1072
|
+
All files will be sent with the same field names: `files[]`.
|
|
927
1073
|
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1074
|
+
## 🆕 HTML Form Posting (browser)
|
|
1075
|
+
|
|
1076
|
+
Pass HTML Form element as a payload to submit it as `multipart/form-data` content.
|
|
931
1077
|
|
|
932
1078
|
```js
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
const form = new FormData();
|
|
936
|
-
form.append('my_field', 'my value');
|
|
937
|
-
form.append('my_buffer', new Buffer(10));
|
|
938
|
-
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
|
1079
|
+
await axios.postForm('https://httpbin.org/post', document.querySelector('#htmlForm'));
|
|
1080
|
+
```
|
|
939
1081
|
|
|
940
|
-
|
|
1082
|
+
`FormData` and `HTMLForm` objects can also be posted as `JSON` by explicitly setting the `Content-Type` header to `application/json`:
|
|
1083
|
+
|
|
1084
|
+
```js
|
|
1085
|
+
await axios.post('https://httpbin.org/post', document.querySelector('#htmlForm'), {
|
|
1086
|
+
headers: {
|
|
1087
|
+
'Content-Type': 'application/json'
|
|
1088
|
+
}
|
|
1089
|
+
})
|
|
941
1090
|
```
|
|
942
1091
|
|
|
1092
|
+
For example, the Form
|
|
1093
|
+
|
|
1094
|
+
```html
|
|
1095
|
+
<form id="form">
|
|
1096
|
+
<input type="text" name="foo" value="1">
|
|
1097
|
+
<input type="text" name="deep.prop" value="2">
|
|
1098
|
+
<input type="text" name="deep prop spaced" value="3">
|
|
1099
|
+
<input type="text" name="baz" value="4">
|
|
1100
|
+
<input type="text" name="baz" value="5">
|
|
1101
|
+
|
|
1102
|
+
<select name="user.age">
|
|
1103
|
+
<option value="value1">Value 1</option>
|
|
1104
|
+
<option value="value2" selected>Value 2</option>
|
|
1105
|
+
<option value="value3">Value 3</option>
|
|
1106
|
+
</select>
|
|
1107
|
+
|
|
1108
|
+
<input type="submit" value="Save">
|
|
1109
|
+
</form>
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
will be submitted as the following JSON object:
|
|
1113
|
+
|
|
1114
|
+
```js
|
|
1115
|
+
{
|
|
1116
|
+
"foo": "1",
|
|
1117
|
+
"deep": {
|
|
1118
|
+
"prop": {
|
|
1119
|
+
"spaced": "3"
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
"baz": [
|
|
1123
|
+
"4",
|
|
1124
|
+
"5"
|
|
1125
|
+
],
|
|
1126
|
+
"user": {
|
|
1127
|
+
"age": "value2"
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
````
|
|
1131
|
+
|
|
1132
|
+
Sending `Blobs`/`Files` as JSON (`base64`) is not currently supported.
|
|
1133
|
+
|
|
943
1134
|
## Semver
|
|
944
1135
|
|
|
945
1136
|
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.
|
|
946
1137
|
|
|
947
1138
|
## Promises
|
|
948
1139
|
|
|
949
|
-
axios depends on a native ES6 Promise implementation to be [supported](
|
|
1140
|
+
axios depends on a native ES6 Promise implementation to be [supported](https://caniuse.com/promises).
|
|
950
1141
|
If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).
|
|
951
1142
|
|
|
952
1143
|
## TypeScript
|
|
953
1144
|
|
|
954
|
-
axios includes [TypeScript](
|
|
1145
|
+
axios includes [TypeScript](https://typescriptlang.org) definitions and a type guard for axios errors.
|
|
955
1146
|
|
|
956
1147
|
```typescript
|
|
957
1148
|
let user: User = null;
|
|
@@ -969,7 +1160,7 @@ try {
|
|
|
969
1160
|
|
|
970
1161
|
## Online one-click setup
|
|
971
1162
|
|
|
972
|
-
You can use Gitpod an online IDE(which is free for Open Source) for contributing or running the examples online.
|
|
1163
|
+
You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online.
|
|
973
1164
|
|
|
974
1165
|
[](https://gitpod.io/#https://github.com/axios/axios/blob/master/examples/server.js)
|
|
975
1166
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Reporting a Vulnerability
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
If you discover a security vulnerability within axios, please submit a report via [huntr.dev](https://huntr.dev/bounties/?target=https%3A%2F%2Fgithub.com%2Faxios%2Faxios). Bounties and CVEs are automatically managed and allocated via the platform.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
All security vulnerabilities will be promptly addressed.
|