@openclaw/slack 2026.6.11 → 2026.6.34
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/dist/account-inspect-api.js +1 -1
- package/dist/{account-inspect-DOtQbKkB.js → account-inspect-ldU97llt.js} +1 -1
- package/dist/{accounts-BPCiCe8y.js → accounts-C9Z3J3lT.js} +8 -1
- package/dist/accounts.runtime-4Xez0y2c.js +2 -0
- package/dist/{action-runtime-DfJK7zS0.js → action-runtime-z9j2PYiO.js} +4 -4
- package/dist/action-runtime.runtime-BuOQERTf.js +2 -0
- package/dist/{actions-OhnDIN4l.js → actions-CCTO1mVi.js} +3 -3
- package/dist/{actions.runtime-DkFXr3-k.js → actions.runtime-BaBCJbO3.js} +1 -1
- package/dist/api.js +12 -12
- package/dist/{approval-handler.runtime-CsFrthnF.js → approval-handler.runtime-Cw1Im48B.js} +2 -2
- package/dist/{channel-COCbJwom.js → channel-DLPyf4p_.js} +23 -17
- package/dist/channel-plugin-api.js +1 -1
- package/dist/{channel.setup-DYQGnKPK.js → channel.setup-RewyjVhG.js} +3 -3
- package/dist/{directory-config-DDVHDmrN.js → directory-config-NDOJRlhK.js} +1 -1
- package/dist/directory-contract-api.js +1 -1
- package/dist/{directory-live-DzOkmJVV.js → directory-live-CeVhaEVq.js} +1 -1
- package/dist/{interactive-replies-D-22gTp3.js → interactive-replies-BBZN1A9T.js} +1 -1
- package/dist/interactive-replies-api.js +1 -1
- package/dist/{message-tool-api--zYyTqrR.js → message-tool-api-OXkQLOkR.js} +2 -2
- package/dist/message-tool-api.js +1 -1
- package/dist/{monitor-Cy-0xYgF.js → monitor-CoF156tn.js} +3 -3
- package/dist/{outbound-adapter-CzX4D5K_.js → outbound-adapter-DqEIkSaa.js} +3 -3
- package/dist/{pipeline.runtime-5R4HgM_7.js → pipeline.runtime-Lp1AVrkR.js} +74 -59
- package/dist/{policy-Bi92bs5t.js → policy-hyhJMisM.js} +1 -1
- package/dist/{probe-BRsYAcGR.js → probe-PFduhlzL.js} +8 -2
- package/dist/{provider-7YKru1TZ.js → provider-CQvIQMod.js} +49 -31
- package/dist/{relay-source-42fP7Ktr.js → relay-source-Bv6k-bAg.js} +1 -1
- package/dist/{replies-Dlxge48k.js → replies-DM1Qi_1b.js} +3 -3
- package/dist/{reply-blocks-BT_sNsDQ.js → reply-blocks-0ofUZd6K.js} +1 -1
- package/dist/runtime-api.js +9 -9
- package/dist/{send-CRoD-UQw.js → send-CrC49d83.js} +3 -3
- package/dist/send.runtime-B_nPiIPk.js +2 -0
- package/dist/{setup-core-BCGzyZhx.js → setup-core-DPMX-Z6o.js} +2 -2
- package/dist/setup-plugin-api.js +1 -1
- package/dist/{setup-surface-D4GE34e2.js → setup-surface-BCB7d1mL.js} +3 -3
- package/dist/{shared-BtJS2bUx.js → shared-CQ2R9FGA.js} +4 -4
- package/dist/{slash-dispatch.runtime-D1qKAWNN.js → slash-dispatch.runtime-CCP3os2O.js} +1 -1
- package/node_modules/agent-base/README.md +145 -0
- package/node_modules/agent-base/dist/src/index.d.ts +78 -0
- package/node_modules/agent-base/dist/src/index.js +203 -0
- package/node_modules/agent-base/dist/src/index.js.map +1 -0
- package/node_modules/agent-base/dist/src/promisify.d.ts +4 -0
- package/node_modules/agent-base/dist/src/promisify.js +18 -0
- package/node_modules/agent-base/dist/src/promisify.js.map +1 -0
- package/node_modules/agent-base/package.json +64 -0
- package/node_modules/agent-base/src/index.ts +345 -0
- package/node_modules/agent-base/src/promisify.ts +33 -0
- package/node_modules/axios/CHANGELOG.md +165 -1
- package/node_modules/axios/README.md +310 -247
- package/node_modules/axios/dist/axios.js +533 -197
- package/node_modules/axios/dist/axios.min.js +3 -3
- package/node_modules/axios/dist/axios.min.js.map +1 -1
- package/node_modules/axios/dist/browser/axios.cjs +564 -161
- package/node_modules/axios/dist/esm/axios.js +564 -161
- package/node_modules/axios/dist/esm/axios.min.js +2 -2
- package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
- package/node_modules/axios/dist/node/axios.cjs +839 -281
- package/node_modules/axios/index.d.cts +11 -4
- package/node_modules/axios/index.d.ts +7 -2
- package/node_modules/axios/lib/adapters/fetch.js +196 -37
- package/node_modules/axios/lib/adapters/http.js +328 -185
- package/node_modules/axios/lib/adapters/xhr.js +2 -1
- package/node_modules/axios/lib/core/Axios.js +4 -2
- package/node_modules/axios/lib/core/AxiosHeaders.js +13 -42
- package/node_modules/axios/lib/core/buildFullPath.js +29 -1
- package/node_modules/axios/lib/core/mergeConfig.js +34 -0
- package/node_modules/axios/lib/defaults/transitional.js +2 -0
- package/node_modules/axios/lib/env/data.js +1 -1
- package/node_modules/axios/lib/helpers/Http2Sessions.js +119 -0
- package/node_modules/axios/lib/helpers/buildURL.js +6 -4
- package/node_modules/axios/lib/helpers/composeSignals.js +48 -47
- package/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +16 -11
- package/node_modules/axios/lib/helpers/formDataToJSON.js +26 -4
- package/node_modules/axios/lib/helpers/formDataToStream.js +2 -2
- package/node_modules/axios/lib/helpers/fromDataURI.js +18 -5
- package/node_modules/axios/lib/helpers/progressEventReducer.js +3 -0
- package/node_modules/axios/lib/helpers/resolveConfig.js +17 -9
- package/node_modules/axios/lib/helpers/sanitizeHeaderValue.js +60 -0
- package/node_modules/axios/lib/helpers/shouldBypassProxy.js +33 -1
- package/node_modules/axios/lib/helpers/toFormData.js +41 -11
- package/node_modules/axios/lib/utils.js +105 -19
- package/node_modules/axios/package.json +31 -13
- package/node_modules/https-proxy-agent/README.md +137 -0
- package/node_modules/https-proxy-agent/dist/agent.d.ts +30 -0
- package/node_modules/https-proxy-agent/dist/agent.js +177 -0
- package/node_modules/https-proxy-agent/dist/agent.js.map +1 -0
- package/node_modules/https-proxy-agent/dist/index.d.ts +23 -0
- package/node_modules/https-proxy-agent/dist/index.js +14 -0
- package/node_modules/https-proxy-agent/dist/index.js.map +1 -0
- package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts +7 -0
- package/node_modules/https-proxy-agent/dist/parse-proxy-response.js +66 -0
- package/node_modules/https-proxy-agent/dist/parse-proxy-response.js.map +1 -0
- package/node_modules/https-proxy-agent/package.json +56 -0
- package/npm-shrinkwrap.json +32 -6
- package/package.json +4 -4
- package/dist/accounts.runtime-CgWgzjLX.js +0 -2
- package/dist/action-runtime.runtime-CIYPRrNy.js +0 -2
- package/dist/send.runtime-C_y65BU0.js +0 -2
- package/node_modules/axios/dist/axios.js.map +0 -1
- package/node_modules/axios/dist/browser/axios.cjs.map +0 -1
- package/node_modules/axios/dist/esm/axios.js.map +0 -1
- package/node_modules/axios/dist/node/axios.cjs.map +0 -1
|
@@ -29,27 +29,10 @@
|
|
|
29
29
|
</td>
|
|
30
30
|
<td align="center" width="50%">
|
|
31
31
|
<a
|
|
32
|
-
href="https://
|
|
33
|
-
style="padding: 10px; display: inline-block"
|
|
32
|
+
href="https://opencollective.com/axios/contribute"
|
|
34
33
|
target="_blank"
|
|
34
|
+
>💜 Become a sponsor</a
|
|
35
35
|
>
|
|
36
|
-
<img
|
|
37
|
-
width="90px"
|
|
38
|
-
height="90px"
|
|
39
|
-
src="https://images.opencollective.com/hopper-security/c4f7de2/avatar.png"
|
|
40
|
-
alt="Hopper Security"
|
|
41
|
-
/>
|
|
42
|
-
</a>
|
|
43
|
-
<p align="center">
|
|
44
|
-
Hopper provides a secure, open-source registry where every component is verified against malware and continuously remediated for vulnerabilities across all versions. In simple terms, Hopper removes the need to manage software supply chain risk altogether.
|
|
45
|
-
</p>
|
|
46
|
-
<p align="center">
|
|
47
|
-
<a
|
|
48
|
-
href="https://hopper.security/?utm_source=axios&utm_medium=readme_sponsorlist&utm_campaign=sponsorship"
|
|
49
|
-
target="_blank"
|
|
50
|
-
><b>hopper.security</b></a
|
|
51
|
-
>
|
|
52
|
-
</p>
|
|
53
36
|
</td>
|
|
54
37
|
</tr>
|
|
55
38
|
</table>
|
|
@@ -142,7 +125,7 @@
|
|
|
142
125
|
</a>
|
|
143
126
|
<p
|
|
144
127
|
align="center"
|
|
145
|
-
title="Hi, we're Descope! We are building something in the authentication space for app developers and can
|
|
128
|
+
title="Hi, we're Descope! We are building something in the authentication space for app developers and can't wait to place it in your hands."
|
|
146
129
|
>
|
|
147
130
|
Reduce user friction, prevent account takeover, and get a 360° view of your customer and agentic identities with the Descope External IAM platform.
|
|
148
131
|
</p>
|
|
@@ -244,14 +227,13 @@
|
|
|
244
227
|
width="71px"
|
|
245
228
|
height="70px"
|
|
246
229
|
src="https://images.opencollective.com/buzzoid-buy-instagram-followers/56a09fe/logo.png"
|
|
247
|
-
alt="Buzzoid"
|
|
230
|
+
alt="Buzzoid - Buy Instagram Followers"
|
|
248
231
|
/>
|
|
249
232
|
</a>
|
|
250
233
|
<p
|
|
251
234
|
align="center"
|
|
252
235
|
>
|
|
253
|
-
|
|
254
|
-
platform
|
|
236
|
+
At Buzzoid, you can buy Instagram followers through a short checkout flow with safety controls. Rated world's #1 IG service since 2012.
|
|
255
237
|
</p>
|
|
256
238
|
<p align="center">
|
|
257
239
|
<a
|
|
@@ -263,17 +245,55 @@
|
|
|
263
245
|
</td>
|
|
264
246
|
<td align="center" width="33.333333333333336%">
|
|
265
247
|
<a
|
|
266
|
-
href="https://
|
|
248
|
+
href="https://twicsy.com/buy-instagram-followers/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship"
|
|
249
|
+
style="padding: 10px; display: inline-block"
|
|
267
250
|
target="_blank"
|
|
268
|
-
>💜 Become a sponsor</a
|
|
269
251
|
>
|
|
252
|
+
<img
|
|
253
|
+
width="71px"
|
|
254
|
+
height="70px"
|
|
255
|
+
src="https://images.opencollective.com/buy-instagram-followers-twicsy/b4c5d7f/logo/256.png?height=256"
|
|
256
|
+
alt="Buy Instagram Followers Twicsy"
|
|
257
|
+
/>
|
|
258
|
+
</a>
|
|
259
|
+
<p
|
|
260
|
+
align="center"
|
|
261
|
+
>
|
|
262
|
+
Buy real Instagram followers from Twicsy. Twicsy has been voted the best site to buy followers from the likes of US Magazine.
|
|
263
|
+
</p>
|
|
264
|
+
<p align="center">
|
|
265
|
+
<a
|
|
266
|
+
href="https://twicsy.com/buy-instagram-followers/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship"
|
|
267
|
+
target="_blank"
|
|
268
|
+
><b>twicsy.com</b></a
|
|
269
|
+
>
|
|
270
|
+
</p>
|
|
270
271
|
</td>
|
|
271
272
|
<td align="center" width="33.333333333333336%">
|
|
272
273
|
<a
|
|
273
|
-
href="https://
|
|
274
|
+
href="https://global.fun88.com/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship"
|
|
275
|
+
style="padding: 10px; display: inline-block"
|
|
274
276
|
target="_blank"
|
|
275
|
-
>💜 Become a sponsor</a
|
|
276
277
|
>
|
|
278
|
+
<img
|
|
279
|
+
width="71px"
|
|
280
|
+
height="70px"
|
|
281
|
+
src="https://images.opencollective.com/fun88-official/bf2843c/logo.png"
|
|
282
|
+
alt="Fun 88"
|
|
283
|
+
/>
|
|
284
|
+
</a>
|
|
285
|
+
<p
|
|
286
|
+
align="center"
|
|
287
|
+
>
|
|
288
|
+
Fun88 is a global online gambling and betting brand founded in 2009, offering a wide range of services including sports betting, live casino games, slots, and virtual gaming.
|
|
289
|
+
</p>
|
|
290
|
+
<p align="center">
|
|
291
|
+
<a
|
|
292
|
+
href="https://global.fun88.com/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship"
|
|
293
|
+
target="_blank"
|
|
294
|
+
><b>global.fun88.com</b></a
|
|
295
|
+
>
|
|
296
|
+
</p>
|
|
277
297
|
</td>
|
|
278
298
|
</tr>
|
|
279
299
|
</table>
|
|
@@ -297,62 +317,61 @@
|
|
|
297
317
|
<div align="center">
|
|
298
318
|
|
|
299
319
|
[](https://www.npmjs.org/package/axios)
|
|
300
|
-
[](https://cdnjs.com/libraries/axios)
|
|
301
320
|
[](https://github.com/axios/axios/actions/workflows/ci.yml)
|
|
302
321
|
[](https://gitpod.io/#https://github.com/axios/axios)
|
|
303
|
-
[](https://coveralls.io/r/mzabriskie/axios)
|
|
304
322
|
[](https://packagephobia.now.sh/result?p=axios)
|
|
305
323
|
[](https://bundlephobia.com/package/axios@latest)
|
|
306
324
|
[](https://npm-stat.com/charts.html?package=axios)
|
|
307
325
|
[](https://gitter.im/mzabriskie/axios)
|
|
308
326
|
[](https://www.codetriage.com/axios/axios)
|
|
309
327
|
[](CONTRIBUTORS.md)
|
|
328
|
+
[](https://agentfriendlycode.com/repo/32)
|
|
310
329
|
|
|
311
330
|
</div>
|
|
312
331
|
|
|
313
|
-
## Table of
|
|
332
|
+
## Table of contents
|
|
314
333
|
|
|
315
334
|
- [Features](#features)
|
|
316
|
-
- [Browser
|
|
335
|
+
- [Browser support](#browser-support)
|
|
317
336
|
- [Installing](#installing)
|
|
318
337
|
- [Package manager](#package-manager)
|
|
319
338
|
- [CDN](#cdn)
|
|
320
339
|
- [Example](#example)
|
|
321
340
|
- [Axios API](#axios-api)
|
|
322
341
|
- [Request method aliases](#request-method-aliases)
|
|
323
|
-
- [Concurrency
|
|
342
|
+
- [Concurrency](#concurrency-deprecated)
|
|
324
343
|
- [Creating an instance](#creating-an-instance)
|
|
325
344
|
- [Instance methods](#instance-methods)
|
|
326
|
-
- [Request
|
|
327
|
-
- [Response
|
|
328
|
-
- [Config
|
|
345
|
+
- [Request config](#request-config)
|
|
346
|
+
- [Response schema](#response-schema)
|
|
347
|
+
- [Config defaults](#config-defaults)
|
|
329
348
|
- [Global axios defaults](#global-axios-defaults)
|
|
330
349
|
- [Custom instance defaults](#custom-instance-defaults)
|
|
331
350
|
- [Config order of precedence](#config-order-of-precedence)
|
|
332
351
|
- [Interceptors](#interceptors)
|
|
333
|
-
- [Multiple
|
|
334
|
-
- [Handling
|
|
335
|
-
- [Handling
|
|
352
|
+
- [Multiple interceptors](#multiple-interceptors)
|
|
353
|
+
- [Handling errors](#handling-errors)
|
|
354
|
+
- [Handling timeouts](#handling-timeouts)
|
|
336
355
|
- [Cancellation](#cancellation)
|
|
337
356
|
- [AbortController](#abortcontroller)
|
|
338
|
-
- [CancelToken
|
|
357
|
+
- [CancelToken](#canceltoken-deprecated)
|
|
339
358
|
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
|
|
340
359
|
- [URLSearchParams](#urlsearchparams)
|
|
341
360
|
- [Query string](#query-string-older-browsers)
|
|
342
|
-
- [
|
|
361
|
+
- [Automatic serialization](#automatic-serialization-to-urlsearchparams)
|
|
343
362
|
- [Using multipart/form-data format](#using-multipartform-data-format)
|
|
344
363
|
- [FormData](#formdata)
|
|
345
|
-
- [
|
|
346
|
-
- [
|
|
347
|
-
- [HTML
|
|
348
|
-
- [
|
|
349
|
-
- [
|
|
350
|
-
- [
|
|
351
|
-
- [
|
|
352
|
-
- [
|
|
353
|
-
- [
|
|
354
|
-
- [
|
|
355
|
-
- [
|
|
364
|
+
- [Automatic serialization](#automatic-serialization-to-formdata)
|
|
365
|
+
- [Posting files](#posting-files)
|
|
366
|
+
- [HTML form posting](#html-form-posting-browser)
|
|
367
|
+
- [Progress capturing](#progress-capturing)
|
|
368
|
+
- [Rate limiting](#rate-limiting)
|
|
369
|
+
- [AxiosHeaders](#axiosheaders)
|
|
370
|
+
- [Fetch adapter](#fetch-adapter)
|
|
371
|
+
- [Custom fetch](#custom-fetch)
|
|
372
|
+
- [Using with Tauri](#using-with-tauri)
|
|
373
|
+
- [Using with SvelteKit](#using-with-sveltekit)
|
|
374
|
+
- [HTTP/2 support](#http2-support)
|
|
356
375
|
- [Semver](#semver)
|
|
357
376
|
- [Promises](#promises)
|
|
358
377
|
- [TypeScript](#typescript)
|
|
@@ -364,17 +383,17 @@
|
|
|
364
383
|
|
|
365
384
|
## Features
|
|
366
385
|
|
|
367
|
-
-
|
|
368
|
-
-
|
|
369
|
-
-
|
|
370
|
-
-
|
|
371
|
-
-
|
|
372
|
-
-
|
|
373
|
-
-
|
|
374
|
-
-
|
|
375
|
-
-
|
|
386
|
+
- Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser.
|
|
387
|
+
- Make [http](https://nodejs.org/api/http.html) requests from Node.js.
|
|
388
|
+
- Use the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API for asynchronous request handling.
|
|
389
|
+
- Intercept requests and responses to add custom logic or transform data.
|
|
390
|
+
- Transform request and response data.
|
|
391
|
+
- Cancel requests with built-in cancellation APIs.
|
|
392
|
+
- Serialize and parse [JSON](https://www.json.org/json-en.html) data.
|
|
393
|
+
- Serialize data objects to `multipart/form-data` or `application/x-www-form-urlencoded`.
|
|
394
|
+
- Add client-side protection against [Cross-Site Request Forgery](https://en.wikipedia.org/wiki/Cross-site_request_forgery).
|
|
376
395
|
|
|
377
|
-
## Browser
|
|
396
|
+
## Browser support
|
|
378
397
|
|
|
379
398
|
| Chrome | Firefox | Safari | Opera | Edge |
|
|
380
399
|
| :------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------: |
|
|
@@ -411,7 +430,7 @@ Using bun:
|
|
|
411
430
|
$ bun add axios
|
|
412
431
|
```
|
|
413
432
|
|
|
414
|
-
Once the package is installed,
|
|
433
|
+
Once the package is installed, import it with `import` or `require`:
|
|
415
434
|
|
|
416
435
|
```js
|
|
417
436
|
import axios, { isCancel, AxiosError } from 'axios';
|
|
@@ -433,14 +452,13 @@ const axios = require('axios');
|
|
|
433
452
|
console.log(axios.isCancel('something'));
|
|
434
453
|
```
|
|
435
454
|
|
|
436
|
-
|
|
455
|
+
Some bundlers and ES6 linters need this form:
|
|
437
456
|
|
|
438
457
|
```js
|
|
439
458
|
import { default as axios } from 'axios';
|
|
440
459
|
```
|
|
441
460
|
|
|
442
|
-
|
|
443
|
-
you can try importing the module package directly:
|
|
461
|
+
In custom or legacy environments, you can import the bundle directly:
|
|
444
462
|
|
|
445
463
|
```js
|
|
446
464
|
const axios = require('axios/dist/browser/axios.cjs'); // browser commonJS bundle (ES2017)
|
|
@@ -480,7 +498,7 @@ axios
|
|
|
480
498
|
params: {
|
|
481
499
|
ID: 12345,
|
|
482
500
|
},
|
|
483
|
-
timeout: 5000, // 5 seconds
|
|
501
|
+
timeout: 5000, // 5 seconds. See "Handling Timeouts" below for matching error handling
|
|
484
502
|
})
|
|
485
503
|
.then(function (response) {
|
|
486
504
|
console.log(response);
|
|
@@ -495,18 +513,26 @@ axios
|
|
|
495
513
|
// Want to use async/await? Add the `async` keyword to your outer function/method.
|
|
496
514
|
async function getUser() {
|
|
497
515
|
try {
|
|
498
|
-
|
|
499
|
-
|
|
516
|
+
// Example: GET request with query parameters
|
|
517
|
+
const response = await axios.get('/user', {
|
|
518
|
+
params: {
|
|
519
|
+
ID: 12345
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
// Using the `params` option improves readability and automatically formats query strings
|
|
524
|
+
|
|
525
|
+
console.log(response);
|
|
500
526
|
} catch (error) {
|
|
501
527
|
console.error(error);
|
|
502
528
|
}
|
|
503
529
|
}
|
|
504
530
|
```
|
|
505
531
|
|
|
506
|
-
>
|
|
532
|
+
> Note: Set a `timeout` in production. Without one, a stalled request can hang
|
|
507
533
|
> indefinitely. See [Handling Timeouts](#handling-timeouts) for the matching error handling.
|
|
508
534
|
|
|
509
|
-
>
|
|
535
|
+
> Note: `async/await` is part of ECMAScript 2017 and is not supported in Internet
|
|
510
536
|
> Explorer and older browsers, so use with caution.
|
|
511
537
|
|
|
512
538
|
Performing a `POST` request
|
|
@@ -591,13 +617,13 @@ For convenience, aliases have been provided for all common request methods.
|
|
|
591
617
|
|
|
592
618
|
##### axios.patch(url[, data[, config]])
|
|
593
619
|
|
|
594
|
-
######
|
|
620
|
+
###### Note
|
|
595
621
|
|
|
596
622
|
When using the alias methods `url`, `method`, and `data` properties don't need to be specified in config.
|
|
597
623
|
|
|
598
|
-
### Concurrency (
|
|
624
|
+
### Concurrency (deprecated)
|
|
599
625
|
|
|
600
|
-
|
|
626
|
+
Use `Promise.all` instead of these helpers.
|
|
601
627
|
|
|
602
628
|
Helper functions for dealing with concurrent requests.
|
|
603
629
|
|
|
@@ -620,7 +646,7 @@ const instance = axios.create({
|
|
|
620
646
|
|
|
621
647
|
### Instance methods
|
|
622
648
|
|
|
623
|
-
The
|
|
649
|
+
The following instance methods are available. Axios merges the specified config with the instance config.
|
|
624
650
|
|
|
625
651
|
##### axios#request(config)
|
|
626
652
|
|
|
@@ -640,11 +666,11 @@ The available instance methods are listed below. The specified config will be me
|
|
|
640
666
|
|
|
641
667
|
##### axios#getUri([config])
|
|
642
668
|
|
|
643
|
-
## Request
|
|
669
|
+
## Request config
|
|
644
670
|
|
|
645
|
-
###
|
|
671
|
+
### Security notice: decompression-bomb protection is opt-in
|
|
646
672
|
|
|
647
|
-
By default `maxContentLength` and `maxBodyLength` are `-1` (unlimited). A malicious or compromised server can return a tiny gzip/deflate/brotli body that expands to gigabytes and exhaust the Node.js process.
|
|
673
|
+
By default `maxContentLength` and `maxBodyLength` are `-1` (unlimited). A malicious or compromised server can return a tiny gzip/deflate/brotli/zstd body that expands to gigabytes and exhaust the Node.js process.
|
|
648
674
|
|
|
649
675
|
If you call servers you do not fully trust, **set a cap**:
|
|
650
676
|
|
|
@@ -655,17 +681,17 @@ axios.defaults.maxBodyLength = 10 * 1024 * 1024;
|
|
|
655
681
|
|
|
656
682
|
See the [security guide](https://axios.rest/pages/misc/security.html) for details.
|
|
657
683
|
|
|
658
|
-
These are
|
|
684
|
+
These config options are available for requests. Only `url` is required. Requests default to `GET` when `method` is not set.
|
|
659
685
|
|
|
660
686
|
```js
|
|
661
687
|
{
|
|
662
|
-
// `url` is the server URL
|
|
688
|
+
// `url` is the server URL for the request
|
|
663
689
|
url: '/user',
|
|
664
690
|
|
|
665
691
|
// `method` is the request method to be used when making the request
|
|
666
692
|
method: 'get', // default
|
|
667
693
|
|
|
668
|
-
// `baseURL`
|
|
694
|
+
// Axios prepends `baseURL` to `url` unless `url` is absolute and `allowAbsoluteUrls` is set to true.
|
|
669
695
|
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
|
|
670
696
|
// to the methods of that instance.
|
|
671
697
|
baseURL: 'https://some-domain.com/api/',
|
|
@@ -694,7 +720,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
694
720
|
return data;
|
|
695
721
|
}],
|
|
696
722
|
|
|
697
|
-
// `parseReviver` is an optional function
|
|
723
|
+
// `parseReviver` is an optional function passed as the
|
|
698
724
|
// second argument (reviver) to JSON.parse()
|
|
699
725
|
parseReviver: function (key, value, context) {
|
|
700
726
|
// In modern environments, context.source provides the raw JSON string
|
|
@@ -747,6 +773,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
747
773
|
// When no `transformRequest` is set, it must be of one of the following types:
|
|
748
774
|
// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
|
|
749
775
|
// - Browser only: FormData, File, Blob
|
|
776
|
+
// - React Native: FormData
|
|
750
777
|
// - Node only: Stream, Buffer, FormData (form-data package)
|
|
751
778
|
data: {
|
|
752
779
|
firstName: 'Fred'
|
|
@@ -763,7 +790,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
763
790
|
data: 'Country=Brasil&City=Belo Horizonte',
|
|
764
791
|
|
|
765
792
|
// `timeout` specifies the number of milliseconds before the request times out.
|
|
766
|
-
// If the request takes longer than `timeout`,
|
|
793
|
+
// If the request takes longer than `timeout`, Axios aborts it.
|
|
767
794
|
timeout: 1000, // default is `0` (no timeout)
|
|
768
795
|
|
|
769
796
|
// `withCredentials` indicates whether or not cross-site Access-Control requests
|
|
@@ -784,6 +811,12 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
784
811
|
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
|
|
785
812
|
// This will set an `Authorization` header, overwriting any existing
|
|
786
813
|
// `Authorization` custom headers you have set using `headers`.
|
|
814
|
+
// If `auth` is omitted, the Node.js HTTP and fetch adapters can read
|
|
815
|
+
// HTTP Basic auth credentials from the request URL, for example
|
|
816
|
+
// `https://user:pass@example.com`. Axios decodes percent-encoded URL
|
|
817
|
+
// credentials, and `auth` takes precedence over URL-embedded credentials.
|
|
818
|
+
// The Node.js HTTP adapter preserves Basic auth on same-origin redirects
|
|
819
|
+
// and strips it on cross-origin redirects.
|
|
787
820
|
// Please note that only HTTP Basic auth is configurable through this parameter.
|
|
788
821
|
// For Bearer tokens and such, use `Authorization` custom headers instead.
|
|
789
822
|
auth: {
|
|
@@ -845,10 +878,12 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
845
878
|
// Do whatever you want with the Axios progress event
|
|
846
879
|
},
|
|
847
880
|
|
|
848
|
-
// `maxContentLength` defines the max size of the
|
|
881
|
+
// `maxContentLength` defines the max size of the response content in bytes.
|
|
882
|
+
// It is enforced by the Node.js HTTP adapter and the fetch adapter.
|
|
849
883
|
maxContentLength: 2000,
|
|
850
884
|
|
|
851
|
-
// `maxBodyLength`
|
|
885
|
+
// `maxBodyLength` defines the max size of the request content in bytes.
|
|
886
|
+
// It is enforced by the Node.js HTTP adapter and the fetch adapter when the body length can be determined.
|
|
852
887
|
maxBodyLength: 2000,
|
|
853
888
|
|
|
854
889
|
// `redact` masks matching config keys when AxiosError#toJSON() is called.
|
|
@@ -857,17 +892,22 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
857
892
|
|
|
858
893
|
// `validateStatus` defines whether to resolve or reject the promise for a given
|
|
859
894
|
// HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
|
|
860
|
-
// or `undefined`), the promise
|
|
861
|
-
// rejected.
|
|
895
|
+
// or `undefined`), Axios resolves the promise; otherwise, Axios rejects it.
|
|
862
896
|
validateStatus: function (status) {
|
|
863
897
|
return status >= 200 && status < 300; // default
|
|
864
898
|
},
|
|
865
899
|
|
|
866
900
|
// `maxRedirects` defines the maximum number of redirects to follow in node.js.
|
|
867
|
-
// If set to 0, no redirects
|
|
901
|
+
// If set to 0, Axios follows no redirects.
|
|
868
902
|
maxRedirects: 21, // default
|
|
869
903
|
|
|
870
|
-
// `
|
|
904
|
+
// `sensitiveHeaders` (Node only option) lists custom secret-bearing headers
|
|
905
|
+
// to remove from cross-origin redirects. Matching is case-insensitive.
|
|
906
|
+
// Same-origin redirects keep these headers. If `maxRedirects` is 0, this
|
|
907
|
+
// option is not used.
|
|
908
|
+
sensitiveHeaders: ['X-API-Key'],
|
|
909
|
+
|
|
910
|
+
// `beforeRedirect` defines a function that Axios calls before redirect.
|
|
871
911
|
// Use this to adjust the request options upon redirecting,
|
|
872
912
|
// to inspect the latest response headers,
|
|
873
913
|
// or to cancel the request by throwing an error
|
|
@@ -883,16 +923,10 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
883
923
|
},
|
|
884
924
|
// Security note:
|
|
885
925
|
// The `beforeRedirect` hook runs after sensitive headers are stripped during redirects.
|
|
886
|
-
//
|
|
887
|
-
//
|
|
888
|
-
//
|
|
889
|
-
|
|
890
|
-
// Security note:
|
|
891
|
-
// The beforeRedirect hook runs after sensitive headers are stripped during redirects.
|
|
892
|
-
// Re-injecting credentials without checking the destination can expose sensitive data.
|
|
893
|
-
// Only add credentials for trusted HTTPS destinations.
|
|
894
|
-
// Avoid re-adding credentials on downgraded redirects.
|
|
895
|
-
|
|
926
|
+
// `follow-redirects` removes credentials on protocol downgrades
|
|
927
|
+
// (HTTPS to HTTP). Because `beforeRedirect` runs after that step,
|
|
928
|
+
// re-injecting credentials without checking the destination can expose
|
|
929
|
+
// sensitive data. Only add credentials for trusted HTTPS destinations.
|
|
896
930
|
|
|
897
931
|
// `socketPath` defines a UNIX Socket to be used in node.js.
|
|
898
932
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
|
|
@@ -911,10 +945,10 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
911
945
|
// `ERR_BAD_OPTION_VALUE`. When null/undefined, no restriction is applied.
|
|
912
946
|
allowedSocketPaths: null, // default
|
|
913
947
|
|
|
914
|
-
// `transport` determines the transport method
|
|
915
|
-
// If defined,
|
|
916
|
-
// the default `http` or `https` library
|
|
917
|
-
// Otherwise, the `httpFollow` or `httpsFollow` library
|
|
948
|
+
// `transport` determines the transport method for the request.
|
|
949
|
+
// If defined, Axios uses it. Otherwise, if `maxRedirects` is 0,
|
|
950
|
+
// Axios uses the default `http` or `https` library, depending on the protocol specified in `protocol`.
|
|
951
|
+
// Otherwise, Axios uses the `httpFollow` or `httpsFollow` library, again depending on the protocol,
|
|
918
952
|
// which can handle redirects.
|
|
919
953
|
transport: undefined, // default
|
|
920
954
|
|
|
@@ -934,15 +968,27 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
934
968
|
// Use `false` to disable proxies, ignoring environment variables.
|
|
935
969
|
// `auth` indicates that HTTP Basic auth should be used to connect to the proxy, and
|
|
936
970
|
// supplies credentials.
|
|
937
|
-
//
|
|
938
|
-
// `Proxy-Authorization`
|
|
971
|
+
// For `http://` targets, axios sends the request to the proxy in
|
|
972
|
+
// forward-proxy mode and stamps `Proxy-Authorization` onto the request
|
|
973
|
+
// headers (overwriting any user-supplied `Proxy-Authorization` header).
|
|
974
|
+
// For `https://` targets, axios establishes a CONNECT tunnel through the
|
|
975
|
+
// proxy and performs TLS end-to-end with the origin; `Proxy-Authorization`
|
|
976
|
+
// is sent on the CONNECT request only, never on the wrapped TLS request,
|
|
977
|
+
// so the proxy never sees the URL, headers, or body. Axios forwards
|
|
978
|
+
// `httpsAgent` TLS options such as `ca`, `cert`, `key`, and
|
|
979
|
+
// `rejectUnauthorized` to the generated tunneling agent, so they still apply
|
|
980
|
+
// to the origin TLS connection.
|
|
981
|
+
// If you supply an `HttpsProxyAgent`, axios leaves tunneling to that agent.
|
|
939
982
|
// If the proxy server uses HTTPS, then you must set the protocol to `https`.
|
|
940
983
|
// A user-supplied `Host` header in `headers` is preserved when forwarding
|
|
941
984
|
// through a proxy (case-insensitive match on `host`/`Host`/`HOST`); this
|
|
942
|
-
// lets you target a virtual host that differs from the request URL
|
|
985
|
+
// lets you target a virtual host that differs from the request URL, for
|
|
943
986
|
// example, hitting `127.0.0.1:4000` while having the proxy treat the
|
|
944
987
|
// request as `example.com`. If no `Host` header is supplied, axios
|
|
945
|
-
// defaults it to the request URL's `hostname:port` as before.
|
|
988
|
+
// defaults it to the request URL's `hostname:port` as before. The Host
|
|
989
|
+
// header is only set in forward-proxy mode (HTTP targets); for HTTPS
|
|
990
|
+
// tunneling the Host header is sent inside the TLS connection, not seen
|
|
991
|
+
// by the proxy.
|
|
946
992
|
proxy: {
|
|
947
993
|
protocol: 'https',
|
|
948
994
|
host: '127.0.0.1',
|
|
@@ -965,6 +1011,8 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
965
1011
|
// `decompress` indicates whether or not the response body should be decompressed
|
|
966
1012
|
// automatically. If set to `true` will also remove the 'content-encoding' header
|
|
967
1013
|
// from the responses objects of all decompressed responses
|
|
1014
|
+
// Axios supports gzip, deflate, brotli, and zstd when the current Node.js
|
|
1015
|
+
// runtime provides the corresponding zlib decompressor.
|
|
968
1016
|
// - Node only (XHR cannot turn off decompression)
|
|
969
1017
|
decompress: true, // default
|
|
970
1018
|
|
|
@@ -994,6 +1042,11 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
994
1042
|
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
|
995
1043
|
clarifyTimeoutError: false,
|
|
996
1044
|
|
|
1045
|
+
// advertise `zstd` in the default Accept-Encoding header when the current
|
|
1046
|
+
// Node.js runtime supports zstd decompression. Axios still decompresses
|
|
1047
|
+
// zstd responses when support exists and `decompress` is true.
|
|
1048
|
+
advertiseZstdAcceptEncoding: false,
|
|
1049
|
+
|
|
997
1050
|
// use the legacy interceptor request/response ordering
|
|
998
1051
|
legacyInterceptorReqResOrdering: true, // default
|
|
999
1052
|
},
|
|
@@ -1038,17 +1091,17 @@ const client = axios.create({
|
|
|
1038
1091
|
});
|
|
1039
1092
|
```
|
|
1040
1093
|
|
|
1041
|
-
##
|
|
1094
|
+
## HTTP/2 support
|
|
1042
1095
|
|
|
1043
|
-
Axios has experimental HTTP/2 support
|
|
1096
|
+
Axios has experimental HTTP/2 support in the Node.js HTTP adapter.
|
|
1044
1097
|
|
|
1045
|
-
Support depends on the runtime environment and Node.js version.
|
|
1098
|
+
Support depends on the runtime environment and Node.js version. Redirects and some adapter behavior may differ from HTTP/1.1.
|
|
1046
1099
|
|
|
1047
|
-
Options like `httpVersion` and `http2Options` are adapter-specific and may not work
|
|
1100
|
+
Options like `httpVersion` and `http2Options` are adapter-specific and may not work the same way in every environment.
|
|
1048
1101
|
|
|
1049
|
-
If HTTP/2
|
|
1102
|
+
If you need HTTP/2, check runtime support or use a custom adapter.
|
|
1050
1103
|
|
|
1051
|
-
## Response
|
|
1104
|
+
## Response schema
|
|
1052
1105
|
|
|
1053
1106
|
The response to a request contains the following information.
|
|
1054
1107
|
|
|
@@ -1078,7 +1131,7 @@ The response to a request contains the following information.
|
|
|
1078
1131
|
}
|
|
1079
1132
|
```
|
|
1080
1133
|
|
|
1081
|
-
When using `then`, you
|
|
1134
|
+
When using `then`, you receive the response like this:
|
|
1082
1135
|
|
|
1083
1136
|
```js
|
|
1084
1137
|
const response = await axios.get('/user/12345');
|
|
@@ -1089,18 +1142,18 @@ console.log(response.headers);
|
|
|
1089
1142
|
console.log(response.config);
|
|
1090
1143
|
```
|
|
1091
1144
|
|
|
1092
|
-
When using `catch`, or passing a [rejection callback](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) as second parameter of `then`, the response
|
|
1145
|
+
When using `catch`, or passing a [rejection callback](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) as the second parameter of `then`, read the response from the `error` object. See [Handling errors](#handling-errors).
|
|
1093
1146
|
|
|
1094
|
-
## Config
|
|
1147
|
+
## Config defaults
|
|
1095
1148
|
|
|
1096
|
-
|
|
1149
|
+
Config defaults apply to every request.
|
|
1097
1150
|
|
|
1098
1151
|
### Global axios defaults
|
|
1099
1152
|
|
|
1100
1153
|
```js
|
|
1101
1154
|
axios.defaults.baseURL = 'https://api.example.com';
|
|
1102
1155
|
|
|
1103
|
-
// Important: If
|
|
1156
|
+
// Important: If you use axios with multiple domains, Axios sends AUTH_TOKEN to all of them.
|
|
1104
1157
|
// See below for an example using Custom instance defaults instead.
|
|
1105
1158
|
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
1106
1159
|
|
|
@@ -1121,7 +1174,7 @@ instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
|
1121
1174
|
|
|
1122
1175
|
### Config order of precedence
|
|
1123
1176
|
|
|
1124
|
-
|
|
1177
|
+
Axios merges config in this order: library defaults from [lib/defaults/index.js](https://github.com/axios/axios/blob/main/lib/defaults/index.js#L49), the instance `defaults` property, and the request `config` argument. Later values take precedence over earlier ones.
|
|
1125
1178
|
|
|
1126
1179
|
```js
|
|
1127
1180
|
// Create an instance using the config defaults provided by the library
|
|
@@ -1180,7 +1233,7 @@ const instance = axios.create();
|
|
|
1180
1233
|
const myInterceptor = instance.interceptors.request.use(function () {
|
|
1181
1234
|
/*...*/
|
|
1182
1235
|
});
|
|
1183
|
-
|
|
1236
|
+
instance.interceptors.request.eject(myInterceptor);
|
|
1184
1237
|
```
|
|
1185
1238
|
|
|
1186
1239
|
You can also clear all interceptors for requests or responses.
|
|
@@ -1223,8 +1276,8 @@ axios.interceptors.request.use(
|
|
|
1223
1276
|
```
|
|
1224
1277
|
|
|
1225
1278
|
If you want to execute a particular interceptor based on a runtime check,
|
|
1226
|
-
you can add a `runWhen` function to the options object. The request interceptor will not
|
|
1227
|
-
of `runWhen` is `false`.
|
|
1279
|
+
you can add a `runWhen` function to the options object. The request interceptor will not run **if and only if** the return
|
|
1280
|
+
of `runWhen` is `false`. Axios calls the function with the config
|
|
1228
1281
|
object (don't forget that you can bind your own arguments to it as well.) This can be handy when you have an
|
|
1229
1282
|
asynchronous request interceptor that only needs to run at certain times.
|
|
1230
1283
|
|
|
@@ -1242,15 +1295,15 @@ axios.interceptors.request.use(
|
|
|
1242
1295
|
);
|
|
1243
1296
|
```
|
|
1244
1297
|
|
|
1245
|
-
>
|
|
1298
|
+
> Note: The options parameter (with `synchronous` and `runWhen` properties) is only supported for request interceptors at the moment.
|
|
1246
1299
|
|
|
1247
|
-
### Interceptor
|
|
1300
|
+
### Interceptor execution order
|
|
1248
1301
|
|
|
1249
|
-
|
|
1302
|
+
Request and response interceptors use different execution orders.
|
|
1250
1303
|
|
|
1251
|
-
Request interceptors
|
|
1304
|
+
Request interceptors run in reverse order (LIFO: last in, first out). The last interceptor added runs first.
|
|
1252
1305
|
|
|
1253
|
-
Response interceptors
|
|
1306
|
+
Response interceptors run in the order they were added (FIFO: first in, first out). The first interceptor added runs first.
|
|
1254
1307
|
|
|
1255
1308
|
Example:
|
|
1256
1309
|
|
|
@@ -1279,37 +1332,33 @@ instance.interceptors.response.use(interceptor('Response Interceptor 3'));
|
|
|
1279
1332
|
// Response Interceptor 3
|
|
1280
1333
|
```
|
|
1281
1334
|
|
|
1282
|
-
### Multiple
|
|
1335
|
+
### Multiple interceptors
|
|
1283
1336
|
|
|
1284
|
-
|
|
1285
|
-
and when the response was fulfilled
|
|
1337
|
+
When a response is fulfilled and multiple response interceptors are registered:
|
|
1286
1338
|
|
|
1287
|
-
-
|
|
1288
|
-
-
|
|
1289
|
-
-
|
|
1290
|
-
-
|
|
1291
|
-
-
|
|
1292
|
-
- then the following fulfillment-interceptor is not called
|
|
1293
|
-
- then the following rejection-interceptor is called
|
|
1294
|
-
- once caught, another following fulfill-interceptor is called again (just like in a promise chain).
|
|
1339
|
+
- Each interceptor runs in registration order.
|
|
1340
|
+
- Each interceptor receives the result from the previous interceptor.
|
|
1341
|
+
- The chain returns the result from the last interceptor.
|
|
1342
|
+
- If a fulfillment interceptor throws, Axios skips the next fulfillment interceptor and calls the next rejection interceptor.
|
|
1343
|
+
- After the error is caught, later fulfillment interceptors run again, just like in a promise chain.
|
|
1295
1344
|
|
|
1296
1345
|
Read [the interceptor tests](./test/specs/interceptors.spec.js) to see all this in code.
|
|
1297
1346
|
|
|
1298
|
-
## Error
|
|
1347
|
+
## Error types
|
|
1299
1348
|
|
|
1300
|
-
|
|
1349
|
+
Axios error messages include details that can help you debug the request.
|
|
1301
1350
|
|
|
1302
|
-
|
|
1351
|
+
Axios errors use this structure:
|
|
1303
1352
|
| Property | Definition |
|
|
1304
1353
|
| -------- | ---------- |
|
|
1305
1354
|
| message | A quick summary of the error message and the status it failed with. |
|
|
1306
1355
|
| name | This defines where the error originated from. For axios, it will always be an 'AxiosError'. |
|
|
1307
|
-
| stack |
|
|
1356
|
+
| stack | Stack trace for the error. |
|
|
1308
1357
|
| config | An axios config object with specific instance configurations defined by the user from when the request was made |
|
|
1309
|
-
| code |
|
|
1358
|
+
| code | Axios error code. The table below lists internal Axios error codes. |
|
|
1310
1359
|
| status | HTTP response status code. See [here](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) for common HTTP response status code meanings.
|
|
1311
1360
|
|
|
1312
|
-
|
|
1361
|
+
These are the internal Axios error codes:
|
|
1313
1362
|
|
|
1314
1363
|
| Code | Definition |
|
|
1315
1364
|
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -1319,16 +1368,16 @@ Below is a list of potential axios identified error:
|
|
|
1319
1368
|
| ERR_DEPRECATED | Deprecated feature or method used in axios. |
|
|
1320
1369
|
| ERR_INVALID_URL | Invalid URL provided for axios request. |
|
|
1321
1370
|
| ECONNABORTED | Typically indicates that the request has been timed out (unless `transitional.clarifyTimeoutError` is set) or aborted by the browser or its plugin. |
|
|
1322
|
-
| ERR_CANCELED |
|
|
1323
|
-
| ETIMEDOUT | Request timed out
|
|
1371
|
+
| ERR_CANCELED | The user explicitly canceled the request with an AbortSignal or CancelToken. |
|
|
1372
|
+
| ETIMEDOUT | Request timed out after exceeding the configured Axios timeout. Set `transitional.clarifyTimeoutError` to `true`; otherwise Axios throws a generic `ECONNABORTED` error. |
|
|
1324
1373
|
| ERR_NETWORK | Network-related issue. In the browser, this error can also be caused by a [CORS](https://developer.mozilla.org/ru/docs/Web/HTTP/Guides/CORS) or [Mixed Content](https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content) policy violation. The browser does not allow the JS code to clarify the real reason for the error caused by security issues, so please check the console. |
|
|
1325
|
-
| ERR_FR_TOO_MANY_REDIRECTS | Request
|
|
1374
|
+
| ERR_FR_TOO_MANY_REDIRECTS | Request exceeded the configured maximum number of redirects. |
|
|
1326
1375
|
| ERR_BAD_RESPONSE | Response cannot be parsed properly or is in an unexpected format. Usually related to a response with `5xx` status code. |
|
|
1327
1376
|
| ERR_BAD_REQUEST | The request has an unexpected format or is missing required parameters. Usually related to a response with `4xx` status code. |
|
|
1328
1377
|
|
|
1329
|
-
## Handling
|
|
1378
|
+
## Handling errors
|
|
1330
1379
|
|
|
1331
|
-
|
|
1380
|
+
By default, Axios rejects responses with status codes outside the 2xx range.
|
|
1332
1381
|
|
|
1333
1382
|
```js
|
|
1334
1383
|
axios.get('/user/12345').catch(function (error) {
|
|
@@ -1351,7 +1400,7 @@ axios.get('/user/12345').catch(function (error) {
|
|
|
1351
1400
|
});
|
|
1352
1401
|
```
|
|
1353
1402
|
|
|
1354
|
-
|
|
1403
|
+
Use `validateStatus` to override the default condition (`status >= 200 && status < 300`) and choose which HTTP status codes should reject.
|
|
1355
1404
|
|
|
1356
1405
|
```js
|
|
1357
1406
|
axios.get('/user/12345', {
|
|
@@ -1361,7 +1410,7 @@ axios.get('/user/12345', {
|
|
|
1361
1410
|
});
|
|
1362
1411
|
```
|
|
1363
1412
|
|
|
1364
|
-
|
|
1413
|
+
Use `toJSON` to get more information about the HTTP error.
|
|
1365
1414
|
|
|
1366
1415
|
```js
|
|
1367
1416
|
axios.get('/user/12345').catch(function (error) {
|
|
@@ -1380,7 +1429,7 @@ axios.get('/user/12345', {
|
|
|
1380
1429
|
});
|
|
1381
1430
|
```
|
|
1382
1431
|
|
|
1383
|
-
## Handling
|
|
1432
|
+
## Handling timeouts
|
|
1384
1433
|
|
|
1385
1434
|
```js
|
|
1386
1435
|
async function fetchWithTimeout() {
|
|
@@ -1414,7 +1463,7 @@ async function fetchWithTimeout() {
|
|
|
1414
1463
|
|
|
1415
1464
|
### AbortController
|
|
1416
1465
|
|
|
1417
|
-
|
|
1466
|
+
Since `v0.22.0`, Axios supports AbortController:
|
|
1418
1467
|
|
|
1419
1468
|
```js
|
|
1420
1469
|
const controller = new AbortController();
|
|
@@ -1430,15 +1479,15 @@ axios
|
|
|
1430
1479
|
controller.abort();
|
|
1431
1480
|
```
|
|
1432
1481
|
|
|
1433
|
-
### CancelToken
|
|
1482
|
+
### CancelToken (deprecated)
|
|
1434
1483
|
|
|
1435
1484
|
You can also cancel a request using a _CancelToken_.
|
|
1436
1485
|
|
|
1437
1486
|
> The axios cancel token API is based on the withdrawn [cancellable promises proposal](https://github.com/tc39/proposal-cancelable-promises).
|
|
1438
1487
|
|
|
1439
|
-
> This API is deprecated since v0.22.0 and
|
|
1488
|
+
> This API is deprecated since v0.22.0 and should not be used in new projects.
|
|
1440
1489
|
|
|
1441
|
-
|
|
1490
|
+
Create a cancel token with the `CancelToken.source` factory:
|
|
1442
1491
|
|
|
1443
1492
|
```js
|
|
1444
1493
|
const CancelToken = axios.CancelToken;
|
|
@@ -1470,7 +1519,7 @@ axios.post(
|
|
|
1470
1519
|
source.cancel('Operation canceled by the user.');
|
|
1471
1520
|
```
|
|
1472
1521
|
|
|
1473
|
-
You can also
|
|
1522
|
+
You can also pass an executor function to the `CancelToken` constructor:
|
|
1474
1523
|
|
|
1475
1524
|
```js
|
|
1476
1525
|
const CancelToken = axios.CancelToken;
|
|
@@ -1487,8 +1536,8 @@ axios.get('/user/12345', {
|
|
|
1487
1536
|
cancel();
|
|
1488
1537
|
```
|
|
1489
1538
|
|
|
1490
|
-
>
|
|
1491
|
-
> If a cancellation token is already cancelled
|
|
1539
|
+
> Note: You can cancel several requests with the same cancel token or abort controller.
|
|
1540
|
+
> If a cancellation token is already cancelled when an Axios request starts, Axios cancels the request immediately without making a real request.
|
|
1492
1541
|
|
|
1493
1542
|
> During the transition period, you can use both cancellation APIs, even for the same request:
|
|
1494
1543
|
|
|
@@ -1496,7 +1545,7 @@ cancel();
|
|
|
1496
1545
|
|
|
1497
1546
|
### URLSearchParams
|
|
1498
1547
|
|
|
1499
|
-
By default, axios serializes JavaScript objects to `JSON`. To send data
|
|
1548
|
+
By default, axios serializes JavaScript objects to `JSON`. To send data as [`application/x-www-form-urlencoded`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST), use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API. It works in most browsers and in [Node](https://nodejs.org/api/url.html#url_class_urlsearchparams) v10 and later.
|
|
1500
1549
|
|
|
1501
1550
|
```js
|
|
1502
1551
|
const params = new URLSearchParams({ foo: 'bar' });
|
|
@@ -1504,9 +1553,9 @@ params.append('extraparam', 'value');
|
|
|
1504
1553
|
axios.post('/foo', params);
|
|
1505
1554
|
```
|
|
1506
1555
|
|
|
1507
|
-
### Query string (
|
|
1556
|
+
### Query string (older browsers)
|
|
1508
1557
|
|
|
1509
|
-
For
|
|
1558
|
+
For very old browsers, use a [polyfill](https://github.com/WebReflection/url-search-params) and make sure it patches the global environment.
|
|
1510
1559
|
|
|
1511
1560
|
Alternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library:
|
|
1512
1561
|
|
|
@@ -1515,7 +1564,7 @@ const qs = require('qs');
|
|
|
1515
1564
|
axios.post('/foo', qs.stringify({ bar: 123 }));
|
|
1516
1565
|
```
|
|
1517
1566
|
|
|
1518
|
-
|
|
1567
|
+
With ES modules:
|
|
1519
1568
|
|
|
1520
1569
|
```js
|
|
1521
1570
|
import qs from 'qs';
|
|
@@ -1531,7 +1580,7 @@ axios(options);
|
|
|
1531
1580
|
|
|
1532
1581
|
### Older Node.js versions
|
|
1533
1582
|
|
|
1534
|
-
For older Node.js engines,
|
|
1583
|
+
For older Node.js engines, use the [`querystring`](https://nodejs.org/api/querystring.html) module:
|
|
1535
1584
|
|
|
1536
1585
|
```js
|
|
1537
1586
|
const querystring = require('querystring');
|
|
@@ -1540,11 +1589,11 @@ axios.post('https://something.com/', querystring.stringify({ foo: 'bar' }));
|
|
|
1540
1589
|
|
|
1541
1590
|
You can also use the [`qs`](https://github.com/ljharb/qs) library.
|
|
1542
1591
|
|
|
1543
|
-
>
|
|
1592
|
+
> Note: 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.
|
|
1544
1593
|
|
|
1545
|
-
###
|
|
1594
|
+
### Automatic serialization to URLSearchParams
|
|
1546
1595
|
|
|
1547
|
-
Axios
|
|
1596
|
+
Axios automatically serializes the data object to urlencoded format if the content-type header is set to "application/x-www-form-urlencoded".
|
|
1548
1597
|
|
|
1549
1598
|
```js
|
|
1550
1599
|
const data = {
|
|
@@ -1562,7 +1611,7 @@ await axios.postForm('https://postman-echo.com/post', data, {
|
|
|
1562
1611
|
});
|
|
1563
1612
|
```
|
|
1564
1613
|
|
|
1565
|
-
The server
|
|
1614
|
+
The server receives these fields:
|
|
1566
1615
|
|
|
1567
1616
|
```js
|
|
1568
1617
|
{
|
|
@@ -1579,7 +1628,7 @@ The server will handle it as:
|
|
|
1579
1628
|
}
|
|
1580
1629
|
```
|
|
1581
1630
|
|
|
1582
|
-
If your backend body
|
|
1631
|
+
If your backend body parser, such as `body-parser` for `express.js`, supports nested object decoding, the server receives the same object structure:
|
|
1583
1632
|
|
|
1584
1633
|
```js
|
|
1585
1634
|
const app = express();
|
|
@@ -1598,8 +1647,9 @@ server = app.listen(3000);
|
|
|
1598
1647
|
|
|
1599
1648
|
### FormData
|
|
1600
1649
|
|
|
1601
|
-
To send
|
|
1602
|
-
|
|
1650
|
+
To send data as `multipart/form-data`, pass a FormData instance as the payload.
|
|
1651
|
+
You do not need to set the `Content-Type` header. Axios detects it from the payload type.
|
|
1652
|
+
For browser, web worker, and React Native `FormData`, leave `Content-Type` unset so the runtime can add the multipart boundary.
|
|
1603
1653
|
|
|
1604
1654
|
```js
|
|
1605
1655
|
const formData = new FormData();
|
|
@@ -1608,7 +1658,7 @@ formData.append('foo', 'bar');
|
|
|
1608
1658
|
axios.post('https://httpbin.org/post', formData);
|
|
1609
1659
|
```
|
|
1610
1660
|
|
|
1611
|
-
In node.js,
|
|
1661
|
+
In node.js, use the [`form-data`](https://github.com/form-data/form-data) library:
|
|
1612
1662
|
|
|
1613
1663
|
```js
|
|
1614
1664
|
const FormData = require('form-data');
|
|
@@ -1623,12 +1673,12 @@ axios.post('https://example.com', form);
|
|
|
1623
1673
|
|
|
1624
1674
|
In node.js, when a `FormData` object provides `getHeaders()`, axios copies all returned headers by default for v1 compatibility. If the `FormData` object is custom or not fully trusted, set `formDataHeaderPolicy: 'content-only'` to copy only `Content-Type` and `Content-Length`, and set any other request headers explicitly with the request `headers` config.
|
|
1625
1675
|
|
|
1626
|
-
###
|
|
1676
|
+
### Automatic serialization to FormData
|
|
1627
1677
|
|
|
1628
|
-
|
|
1678
|
+
Since `v0.27.0`, Axios can serialize an object to FormData if the request `Content-Type`
|
|
1629
1679
|
header is set to `multipart/form-data`.
|
|
1630
1680
|
|
|
1631
|
-
|
|
1681
|
+
This request submits data as FormData in browsers and Node.js:
|
|
1632
1682
|
|
|
1633
1683
|
```js
|
|
1634
1684
|
import axios from 'axios';
|
|
@@ -1646,10 +1696,9 @@ axios
|
|
|
1646
1696
|
.then(({ data }) => console.log(data));
|
|
1647
1697
|
```
|
|
1648
1698
|
|
|
1649
|
-
|
|
1699
|
+
The Node.js build uses the [`form-data`](https://github.com/form-data/form-data) polyfill by default.
|
|
1650
1700
|
|
|
1651
|
-
You can
|
|
1652
|
-
but you probably won't need it in most cases:
|
|
1701
|
+
You can override the FormData class with the `env.FormData` config option, but most applications do not need this:
|
|
1653
1702
|
|
|
1654
1703
|
```js
|
|
1655
1704
|
const axios = require('axios');
|
|
@@ -1668,30 +1717,30 @@ axios
|
|
|
1668
1717
|
.then(({ data }) => console.log(data));
|
|
1669
1718
|
```
|
|
1670
1719
|
|
|
1671
|
-
Axios FormData serializer supports
|
|
1720
|
+
The Axios FormData serializer supports these special endings:
|
|
1672
1721
|
|
|
1673
1722
|
- `{}` - serialize the value with JSON.stringify
|
|
1674
1723
|
- `[]` - unwrap the array-like object as separate fields with the same key
|
|
1675
1724
|
|
|
1676
|
-
>
|
|
1725
|
+
> Note: Arrays and FileList objects are unwrapped by default.
|
|
1677
1726
|
|
|
1678
1727
|
FormData serializer supports additional options via `config.formSerializer: object` property to handle rare cases:
|
|
1679
1728
|
|
|
1680
|
-
- `visitor: Function` - user-defined visitor function that
|
|
1729
|
+
- `visitor: Function` - user-defined visitor function that Axios calls recursively to serialize the data object
|
|
1681
1730
|
to a `FormData` object by following custom rules.
|
|
1682
1731
|
|
|
1683
1732
|
- `dots: boolean = false` - use dot notation instead of brackets to serialize arrays and objects;
|
|
1684
1733
|
|
|
1685
1734
|
- `metaTokens: boolean = true` - add the special ending (e.g `user{}: '{"name": "John"}'`) in the FormData key.
|
|
1686
|
-
|
|
1735
|
+
A backend body parser can use this meta-information to parse the value as JSON.
|
|
1687
1736
|
|
|
1688
|
-
- `indexes: null|false|true = false` - controls how
|
|
1737
|
+
- `indexes: null|false|true = false` - controls how Axios adds indexes to unwrapped keys of `flat` array-like objects.
|
|
1689
1738
|
- `null` - don't add brackets (`arr: 1`, `arr: 2`, `arr: 3`)
|
|
1690
1739
|
- `false`(default) - add empty brackets (`arr[]: 1`, `arr[]: 2`, `arr[]: 3`)
|
|
1691
1740
|
- `true` - add brackets with indexes (`arr[0]: 1`, `arr[1]: 2`, `arr[2]: 3`)
|
|
1692
1741
|
- `maxDepth: number = 100` - maximum object nesting depth the serializer will recurse into. If the
|
|
1693
1742
|
input object exceeds this depth, an `AxiosError` with `code: 'ERR_FORM_DATA_DEPTH_EXCEEDED'` is
|
|
1694
|
-
thrown instead of overflowing the call stack. This protects server
|
|
1743
|
+
thrown instead of overflowing the call stack. This protects server applications from DoS
|
|
1695
1744
|
attacks via deeply nested payloads. Set to `Infinity` to disable the limit and restore pre-fix behaviour.
|
|
1696
1745
|
|
|
1697
1746
|
```js
|
|
@@ -1702,7 +1751,7 @@ axios.postForm('/api', data, { formSerializer: { maxDepth: 200 } });
|
|
|
1702
1751
|
axios.get('/api', { params: data, paramsSerializer: { maxDepth: 200 } });
|
|
1703
1752
|
```
|
|
1704
1753
|
|
|
1705
|
-
|
|
1754
|
+
Given this object:
|
|
1706
1755
|
|
|
1707
1756
|
```js
|
|
1708
1757
|
const obj = {
|
|
@@ -1717,7 +1766,7 @@ const obj = {
|
|
|
1717
1766
|
};
|
|
1718
1767
|
```
|
|
1719
1768
|
|
|
1720
|
-
The
|
|
1769
|
+
The Axios serializer appends these fields:
|
|
1721
1770
|
|
|
1722
1771
|
```js
|
|
1723
1772
|
const formData = new FormData();
|
|
@@ -1735,12 +1784,11 @@ formData.append('users[1][surname]', 'Anderson');
|
|
|
1735
1784
|
formData.append('obj2{}', '[{"x":1}]');
|
|
1736
1785
|
```
|
|
1737
1786
|
|
|
1738
|
-
Axios supports
|
|
1739
|
-
which are just the corresponding http methods with the `Content-Type` header preset to `multipart/form-data`.
|
|
1787
|
+
Axios supports `postForm`, `putForm`, and `patchForm` as shortcuts for the matching HTTP methods with the `Content-Type` header preset to `multipart/form-data`.
|
|
1740
1788
|
|
|
1741
|
-
##
|
|
1789
|
+
## Posting files
|
|
1742
1790
|
|
|
1743
|
-
|
|
1791
|
+
Submit a single file:
|
|
1744
1792
|
|
|
1745
1793
|
```js
|
|
1746
1794
|
await axios.postForm('https://httpbin.org/post', {
|
|
@@ -1763,9 +1811,9 @@ await axios.postForm('https://httpbin.org/post', {
|
|
|
1763
1811
|
await axios.postForm('https://httpbin.org/post', document.querySelector('#fileInput').files);
|
|
1764
1812
|
```
|
|
1765
1813
|
|
|
1766
|
-
|
|
1814
|
+
Axios sends all files with the same field name: `files[]`.
|
|
1767
1815
|
|
|
1768
|
-
##
|
|
1816
|
+
## HTML form posting (browser)
|
|
1769
1817
|
|
|
1770
1818
|
Pass an HTML Form element as a payload to submit it as `multipart/form-data` content.
|
|
1771
1819
|
|
|
@@ -1803,7 +1851,7 @@ For example, the Form
|
|
|
1803
1851
|
</form>
|
|
1804
1852
|
```
|
|
1805
1853
|
|
|
1806
|
-
|
|
1854
|
+
submits this JSON object:
|
|
1807
1855
|
|
|
1808
1856
|
```js
|
|
1809
1857
|
{
|
|
@@ -1825,10 +1873,10 @@ will be submitted as the following JSON object:
|
|
|
1825
1873
|
|
|
1826
1874
|
Sending `Blobs`/`Files` as JSON (`base64`) is not currently supported.
|
|
1827
1875
|
|
|
1828
|
-
##
|
|
1876
|
+
## Progress capturing
|
|
1829
1877
|
|
|
1830
|
-
Axios
|
|
1831
|
-
|
|
1878
|
+
Axios can capture request upload and download progress in browsers and Node.js.
|
|
1879
|
+
Progress events are limited to `3` times per second.
|
|
1832
1880
|
|
|
1833
1881
|
```js
|
|
1834
1882
|
await axios.post(url, data, {
|
|
@@ -1874,14 +1922,14 @@ const { data } = await axios.post(SERVER_URL, readableStream, {
|
|
|
1874
1922
|
});
|
|
1875
1923
|
```
|
|
1876
1924
|
|
|
1877
|
-
>
|
|
1925
|
+
> Note:
|
|
1878
1926
|
> Capturing FormData upload progress is not currently supported in node.js environments.
|
|
1879
1927
|
|
|
1880
|
-
>
|
|
1881
|
-
>
|
|
1882
|
-
>
|
|
1928
|
+
> Warning:
|
|
1929
|
+
> Set `maxRedirects: 0` when uploading streams in node.js.
|
|
1930
|
+
> The follow-redirects package buffers the entire stream in RAM and does not follow the "backpressure" algorithm.
|
|
1883
1931
|
|
|
1884
|
-
##
|
|
1932
|
+
## Rate limiting
|
|
1885
1933
|
|
|
1886
1934
|
Download and upload rate limits can only be set for the http adapter (node.js):
|
|
1887
1935
|
|
|
@@ -1895,25 +1943,24 @@ const { data } = await axios.post(LOCAL_SERVER_URL, myBuffer, {
|
|
|
1895
1943
|
});
|
|
1896
1944
|
```
|
|
1897
1945
|
|
|
1898
|
-
##
|
|
1946
|
+
## AxiosHeaders
|
|
1899
1947
|
|
|
1900
|
-
Axios
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
The old approach of directly manipulating the headers object is still available, but deprecated and not recommended for future usage.
|
|
1948
|
+
Axios includes an `AxiosHeaders` class for working with headers through a Map-like API.
|
|
1949
|
+
HTTP header names are case-insensitive, but Axios keeps the original header case for style and for servers that incorrectly depend on case.
|
|
1950
|
+
Directly manipulating the headers object still works, but it is deprecated.
|
|
1904
1951
|
|
|
1905
1952
|
### Working with headers
|
|
1906
1953
|
|
|
1907
|
-
An AxiosHeaders
|
|
1908
|
-
|
|
1954
|
+
An `AxiosHeaders` instance can contain several internal value types that control setting and merging.
|
|
1955
|
+
Axios gets the final headers object with string values by calling `toJSON`.
|
|
1909
1956
|
|
|
1910
1957
|
> Note: By JSON here we mean an object consisting only of string values intended to be sent over the network.
|
|
1911
1958
|
|
|
1912
1959
|
The header value can be one of the following types:
|
|
1913
1960
|
|
|
1914
|
-
- `string` - normal string value
|
|
1961
|
+
- `string` - normal string value sent to the server
|
|
1915
1962
|
- `null` - skip header when rendering to JSON
|
|
1916
|
-
- `false` - skip header when rendering to JSON
|
|
1963
|
+
- `false` - skip header when rendering to JSON. Also indicates that the `set` method must be called with `rewrite` set to `true`
|
|
1917
1964
|
to overwrite this value (Axios uses this internally to allow users to opt out of installing certain headers like `User-Agent` or `Content-Type`)
|
|
1918
1965
|
- `undefined` - value is not set
|
|
1919
1966
|
|
|
@@ -1930,7 +1977,7 @@ axios.interceptors.request.use((request: InternalAxiosRequestConfig) => {
|
|
|
1930
1977
|
'My-set-header2': 'my-set-value2',
|
|
1931
1978
|
});
|
|
1932
1979
|
|
|
1933
|
-
request.headers.set('User-Agent', false); //
|
|
1980
|
+
request.headers.set('User-Agent', false); // prevent Axios from setting this header later
|
|
1934
1981
|
|
|
1935
1982
|
request.headers.setContentType('text/plain');
|
|
1936
1983
|
|
|
@@ -1998,7 +2045,7 @@ Constructs a new `AxiosHeaders` instance.
|
|
|
1998
2045
|
constructor(headers?: RawAxiosHeaders | AxiosHeaders | string);
|
|
1999
2046
|
```
|
|
2000
2047
|
|
|
2001
|
-
If the headers object is a string,
|
|
2048
|
+
If the headers object is a string, Axios parses it as raw HTTP headers.
|
|
2002
2049
|
|
|
2003
2050
|
```js
|
|
2004
2051
|
const headers = new AxiosHeaders(`
|
|
@@ -2029,7 +2076,9 @@ The `rewrite` argument controls the overwriting behavior:
|
|
|
2029
2076
|
- `undefined` (default) - overwrite the header unless its value is set to `false`
|
|
2030
2077
|
- `true` - rewrite anyway
|
|
2031
2078
|
|
|
2032
|
-
The option can also accept a user-defined function that determines whether the value
|
|
2079
|
+
The option can also accept a user-defined function that determines whether to overwrite the value.
|
|
2080
|
+
|
|
2081
|
+
Empty or whitespace-only header names are ignored.
|
|
2033
2082
|
|
|
2034
2083
|
Returns `this`.
|
|
2035
2084
|
|
|
@@ -2093,7 +2142,7 @@ clear(matcher?: AxiosHeaderMatcher): boolean;
|
|
|
2093
2142
|
```
|
|
2094
2143
|
|
|
2095
2144
|
Removes all headers.
|
|
2096
|
-
Unlike the `delete` method matcher, this optional matcher
|
|
2145
|
+
Unlike the `delete` method matcher, this optional matcher matches the header name rather than the value.
|
|
2097
2146
|
|
|
2098
2147
|
```ts
|
|
2099
2148
|
const headers = new AxiosHeaders({
|
|
@@ -2137,17 +2186,18 @@ Returns `this`.
|
|
|
2137
2186
|
concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>): AxiosHeaders;
|
|
2138
2187
|
```
|
|
2139
2188
|
|
|
2140
|
-
Merges the instance with targets into a new `AxiosHeaders` instance. If the target is a string,
|
|
2189
|
+
Merges the instance with targets into a new `AxiosHeaders` instance. If the target is a string, Axios parses it as raw HTTP headers.
|
|
2141
2190
|
|
|
2142
2191
|
Returns a new `AxiosHeaders` instance.
|
|
2143
2192
|
|
|
2144
2193
|
### AxiosHeaders#toJSON(asStrings?)
|
|
2145
2194
|
|
|
2146
2195
|
```
|
|
2147
|
-
toJSON(asStrings
|
|
2196
|
+
toJSON(asStrings: true): Record<string, string>;
|
|
2197
|
+
toJSON(asStrings?: false): Record<string, string | string[]>;
|
|
2148
2198
|
```
|
|
2149
2199
|
|
|
2150
|
-
|
|
2200
|
+
Resolves all internal header values into a new null prototype object.
|
|
2151
2201
|
Set `asStrings` to true to resolve arrays as a string containing all elements, separated by commas.
|
|
2152
2202
|
|
|
2153
2203
|
### AxiosHeaders.from(thing?)
|
|
@@ -2157,7 +2207,7 @@ from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
|
|
2157
2207
|
```
|
|
2158
2208
|
|
|
2159
2209
|
Returns a new `AxiosHeaders` instance created from the raw headers passed in,
|
|
2160
|
-
or
|
|
2210
|
+
or returns the given headers object if it's already an `AxiosHeaders` instance.
|
|
2161
2211
|
|
|
2162
2212
|
### AxiosHeaders.concat(...targets)
|
|
2163
2213
|
|
|
@@ -2181,11 +2231,10 @@ The following shortcuts are available:
|
|
|
2181
2231
|
|
|
2182
2232
|
- `setContentEncoding`, `getContentEncoding`, `hasContentEncoding`
|
|
2183
2233
|
|
|
2184
|
-
##
|
|
2234
|
+
## Fetch adapter
|
|
2185
2235
|
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
To use it by default, it must be selected explicitly:
|
|
2236
|
+
Axios introduced the fetch adapter in `v1.7.0`. By default, Axios uses it when the `xhr` and `http` adapters are not available in the build or not supported by the environment.
|
|
2237
|
+
To use it by default, select it explicitly:
|
|
2189
2238
|
|
|
2190
2239
|
```js
|
|
2191
2240
|
const { data } = axios.get(url, {
|
|
@@ -2203,20 +2252,21 @@ const fetchAxios = axios.create({
|
|
|
2203
2252
|
const { data } = fetchAxios.get(url);
|
|
2204
2253
|
```
|
|
2205
2254
|
|
|
2206
|
-
The adapter supports the same
|
|
2207
|
-
|
|
2255
|
+
The adapter supports the same features as the `xhr` adapter, including upload and download progress capturing.
|
|
2256
|
+
It also supports response types such as `stream` and `formdata` when the environment supports them.
|
|
2208
2257
|
|
|
2209
|
-
|
|
2258
|
+
When `auth` is omitted, the fetch adapter can read HTTP Basic auth credentials from the request URL, for example `https://user:pass@example.com`. Percent-encoded URL credentials are decoded before the `Authorization` header is generated, and `auth` takes precedence over URL-embedded credentials.
|
|
2210
2259
|
|
|
2211
|
-
|
|
2212
|
-
You can pass a custom `fetch` function, `Request`, and `Response` constructors via env config.
|
|
2213
|
-
This can be helpful in case of custom environments & app frameworks.
|
|
2260
|
+
### Custom fetch
|
|
2214
2261
|
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2262
|
+
Since `v1.12.0`, you can configure the fetch adapter to use a custom fetch API instead of environment globals.
|
|
2263
|
+
Pass a custom `fetch` function, `Request`, and `Response` constructors through `env` config.
|
|
2264
|
+
This helps in custom environments and app frameworks.
|
|
2218
2265
|
|
|
2219
|
-
|
|
2266
|
+
When using a custom fetch, you may also need to set custom `Request` and `Response` constructors. If you do not set them, Axios uses the global objects.
|
|
2267
|
+
If your custom fetch API does not provide these objects and the globals are incompatible with it, pass `null` to disable them inside the fetch adapter.
|
|
2268
|
+
|
|
2269
|
+
> Note: Setting `Request` and `Response` to `null` prevents the fetch adapter from capturing upload and download progress.
|
|
2220
2270
|
|
|
2221
2271
|
Basic example:
|
|
2222
2272
|
|
|
@@ -2236,7 +2286,7 @@ const instance = axios.create({
|
|
|
2236
2286
|
});
|
|
2237
2287
|
```
|
|
2238
2288
|
|
|
2239
|
-
####
|
|
2289
|
+
#### Using with Tauri
|
|
2240
2290
|
|
|
2241
2291
|
A minimal example of setting up Axios for use in a [Tauri](https://tauri.app/plugin/http-client/) app with a platform fetch function that ignores CORS policy for requests.
|
|
2242
2292
|
|
|
@@ -2257,10 +2307,9 @@ const instance = axios.create({
|
|
|
2257
2307
|
const { data } = await instance.get('https://google.com');
|
|
2258
2308
|
```
|
|
2259
2309
|
|
|
2260
|
-
####
|
|
2310
|
+
#### Using with SvelteKit
|
|
2261
2311
|
|
|
2262
|
-
[SvelteKit](https://svelte.dev/docs/kit/web-standards#Fetch-APIs)
|
|
2263
|
-
which makes it incompatible with the standard URL API. So, Axios must be configured to use the custom fetch API:
|
|
2312
|
+
[SvelteKit](https://svelte.dev/docs/kit/web-standards#Fetch-APIs) uses a custom fetch function for server rendering in `load` functions. It also uses relative paths, which are incompatible with the standard URL API. Configure Axios to use SvelteKit's custom fetch API:
|
|
2264
2313
|
|
|
2265
2314
|
```js
|
|
2266
2315
|
export async function load({ fetch }) {
|
|
@@ -2277,13 +2326,13 @@ export async function load({ fetch }) {
|
|
|
2277
2326
|
}
|
|
2278
2327
|
```
|
|
2279
2328
|
|
|
2280
|
-
#### HTTP/2
|
|
2329
|
+
#### HTTP/2 support
|
|
2281
2330
|
|
|
2282
|
-
Axios supports HTTP/2
|
|
2331
|
+
Axios supports HTTP/2 through the Node.js `http` adapter, introduced in v1.13.0.
|
|
2283
2332
|
|
|
2284
|
-
|
|
2333
|
+
Support depends on the runtime environment. Axios relies on Node.js APIs, so HTTP/2 works in supported Node.js versions but may not work in other environments such as Bun or Deno.
|
|
2285
2334
|
|
|
2286
|
-
Options like `httpVersion` and `http2Options` are adapter-specific and may not behave
|
|
2335
|
+
Options like `httpVersion` and `http2Options` are adapter-specific and may not behave the same way in every environment.
|
|
2287
2336
|
|
|
2288
2337
|
Note: HTTP/2 redirects are currently not supported by the HTTP/2 adapter.
|
|
2289
2338
|
|
|
@@ -2305,7 +2354,7 @@ const { data, headers, status } = await axios.post('https://httpbin.org/post', f
|
|
|
2305
2354
|
|
|
2306
2355
|
## Semver
|
|
2307
2356
|
|
|
2308
|
-
|
|
2357
|
+
Axios follows [semver](https://semver.org/) since `v1.0.0`.
|
|
2309
2358
|
|
|
2310
2359
|
## Promises
|
|
2311
2360
|
|
|
@@ -2330,10 +2379,24 @@ try {
|
|
|
2330
2379
|
}
|
|
2331
2380
|
```
|
|
2332
2381
|
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2382
|
+
Use `axios.isCancel<T>()` to narrow cancellation errors to `CanceledError<T>`:
|
|
2383
|
+
|
|
2384
|
+
```typescript
|
|
2385
|
+
const controller = new AbortController();
|
|
2386
|
+
|
|
2387
|
+
try {
|
|
2388
|
+
await axios.get<User>('/user?ID=12345', { signal: controller.signal });
|
|
2389
|
+
} catch (error) {
|
|
2390
|
+
if (axios.isCancel<User>(error)) {
|
|
2391
|
+
handleCancellation(error);
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
```
|
|
2395
|
+
|
|
2396
|
+
Because axios publishes an ESM default export and a CJS `module.exports`, TypeScript has a few caveats.
|
|
2397
|
+
The recommended setting is `"moduleResolution": "node16"`, which is implied by `"module": "node16"`. This requires TypeScript 4.7 or greater.
|
|
2398
|
+
If you use ESM, your settings should be fine.
|
|
2399
|
+
If you compile TypeScript to CJS and can't use `"moduleResolution": "node 16"`, enable `esModuleInterop`.
|
|
2337
2400
|
If you use TypeScript to type check CJS JavaScript code, your only option is to use `"moduleResolution": "node16"`.
|
|
2338
2401
|
|
|
2339
2402
|
You can also create a custom instance with typed interceptors:
|
|
@@ -2354,7 +2417,7 @@ apiClient.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
|
|
2354
2417
|
|
|
2355
2418
|
## Online one-click setup
|
|
2356
2419
|
|
|
2357
|
-
You can use Gitpod,
|
|
2420
|
+
You can use Gitpod, a free online IDE for open source projects, to contribute or run the examples online.
|
|
2358
2421
|
|
|
2359
2422
|
[](https://gitpod.io/#https://github.com/axios/axios/blob/main/examples/server.js)
|
|
2360
2423
|
|
|
@@ -2373,7 +2436,7 @@ npm rebuild husky && npx husky
|
|
|
2373
2436
|
|
|
2374
2437
|
Run those two commands once per fresh checkout. You do **not** need to re-run them after every subsequent `npm install`.
|
|
2375
2438
|
|
|
2376
|
-
Do not remove `ignore-scripts=true` from `.npmrc` to "fix" this
|
|
2439
|
+
Do not remove `ignore-scripts=true` from `.npmrc` to "fix" this. That reopens the lifecycle-script attack surface for every other package in the tree. All CI workflows already invoke npm with `--ignore-scripts`, so local behaviour matches CI.
|
|
2377
2440
|
|
|
2378
2441
|
## Resources
|
|
2379
2442
|
|
|
@@ -2384,7 +2447,7 @@ Do not remove `ignore-scripts=true` from `.npmrc` to "fix" this — that re-open
|
|
|
2384
2447
|
|
|
2385
2448
|
## Credits
|
|
2386
2449
|
|
|
2387
|
-
axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http)
|
|
2450
|
+
axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) in [AngularJS](https://angularjs.org/). It provides a standalone `$http`-like service for use outside AngularJS.
|
|
2388
2451
|
|
|
2389
2452
|
## License
|
|
2390
2453
|
|