@st-gr/sail-proxy 0.9.2 → 0.9.3
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/bundled/gateway/node_modules/.package-lock.json +132 -83
- package/bundled/gateway/node_modules/axios/CHANGELOG.md +0 -42
- package/bundled/gateway/node_modules/axios/README.md +237 -237
- package/bundled/gateway/node_modules/axios/dist/axios.js +21 -113
- package/bundled/gateway/node_modules/axios/dist/axios.js.map +1 -0
- package/bundled/gateway/node_modules/axios/dist/axios.min.js +2 -2
- package/bundled/gateway/node_modules/axios/dist/axios.min.js.map +1 -1
- package/bundled/gateway/node_modules/axios/dist/browser/axios.cjs +15 -121
- package/bundled/gateway/node_modules/axios/dist/browser/axios.cjs.map +1 -0
- package/bundled/gateway/node_modules/axios/dist/esm/axios.js +15 -121
- package/bundled/gateway/node_modules/axios/dist/esm/axios.js.map +1 -0
- package/bundled/gateway/node_modules/axios/dist/esm/axios.min.js +2 -2
- package/bundled/gateway/node_modules/axios/dist/esm/axios.min.js.map +1 -1
- package/bundled/gateway/node_modules/axios/dist/node/axios.cjs +107 -249
- package/bundled/gateway/node_modules/axios/dist/node/axios.cjs.map +1 -0
- package/bundled/gateway/node_modules/axios/index.d.cts +3 -8
- package/bundled/gateway/node_modules/axios/index.d.ts +1 -4
- package/bundled/gateway/node_modules/axios/lib/adapters/fetch.js +0 -79
- package/bundled/gateway/node_modules/axios/lib/adapters/http.js +118 -62
- package/bundled/gateway/node_modules/axios/lib/core/Axios.js +0 -1
- package/bundled/gateway/node_modules/axios/lib/core/AxiosHeaders.js +2 -2
- package/bundled/gateway/node_modules/axios/lib/defaults/transitional.js +0 -1
- package/bundled/gateway/node_modules/axios/lib/env/data.js +1 -1
- package/bundled/gateway/node_modules/axios/lib/helpers/buildURL.js +1 -1
- package/bundled/gateway/node_modules/axios/lib/helpers/formDataToStream.js +2 -2
- package/bundled/gateway/node_modules/axios/lib/helpers/resolveConfig.js +6 -12
- package/bundled/gateway/node_modules/axios/lib/helpers/toFormData.js +1 -1
- package/bundled/gateway/node_modules/axios/lib/utils.js +2 -23
- package/bundled/gateway/node_modules/axios/package.json +13 -29
- package/bundled/gateway/node_modules/body-parser/HISTORY.md +0 -14
- package/bundled/gateway/node_modules/body-parser/SECURITY.md +25 -0
- package/bundled/gateway/node_modules/body-parser/lib/types/json.js +5 -1
- package/bundled/gateway/node_modules/body-parser/lib/types/urlencoded.js +15 -7
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/.editorconfig +46 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/.eslintrc +38 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/.github/FUNDING.yml +12 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/.nycrc +13 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/CHANGELOG.md +600 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/LICENSE.md +29 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/README.md +709 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/dist/qs.js +90 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/lib/formats.js +23 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/lib/index.js +11 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/lib/parse.js +296 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/lib/stringify.js +351 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/lib/utils.js +265 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/package.json +91 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/test/empty-keys-cases.js +267 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/test/parse.js +1170 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/test/stringify.js +1298 -0
- package/bundled/gateway/node_modules/body-parser/node_modules/qs/test/utils.js +136 -0
- package/bundled/gateway/node_modules/body-parser/package.json +10 -9
- package/bundled/gateway/node_modules/cookie/index.js +35 -24
- package/bundled/gateway/node_modules/cookie/package.json +1 -1
- package/bundled/gateway/node_modules/cookie-signature/History.md +1 -5
- package/bundled/gateway/node_modules/cookie-signature/index.js +6 -6
- package/bundled/gateway/node_modules/cookie-signature/package.json +2 -2
- package/bundled/gateway/node_modules/express/History.md +0 -43
- package/bundled/gateway/node_modules/express/lib/response.js +0 -1
- package/bundled/gateway/node_modules/express/lib/utils.js +1 -2
- package/bundled/gateway/node_modules/express/node_modules/qs/.editorconfig +43 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/.eslintrc +38 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/.github/FUNDING.yml +12 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/.nycrc +13 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/CHANGELOG.md +546 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/LICENSE.md +29 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/README.md +625 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/dist/qs.js +2054 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/lib/formats.js +23 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/lib/index.js +11 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/lib/parse.js +263 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/lib/stringify.js +326 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/lib/utils.js +252 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/package.json +77 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/test/parse.js +855 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/test/stringify.js +909 -0
- package/bundled/gateway/node_modules/express/node_modules/qs/test/utils.js +136 -0
- package/bundled/gateway/node_modules/express/package.json +17 -21
- package/bundled/gateway/node_modules/finalhandler/HISTORY.md +0 -21
- package/bundled/gateway/node_modules/finalhandler/README.md +2 -2
- package/bundled/gateway/node_modules/finalhandler/index.js +2 -7
- package/bundled/gateway/node_modules/finalhandler/node_modules/encodeurl/HISTORY.md +14 -0
- package/bundled/gateway/node_modules/finalhandler/node_modules/encodeurl/LICENSE +22 -0
- package/bundled/gateway/node_modules/finalhandler/node_modules/encodeurl/README.md +128 -0
- package/bundled/gateway/node_modules/finalhandler/node_modules/encodeurl/index.js +60 -0
- package/bundled/gateway/node_modules/finalhandler/node_modules/encodeurl/package.json +40 -0
- package/bundled/gateway/node_modules/finalhandler/package.json +9 -10
- package/bundled/gateway/node_modules/http-errors/HISTORY.md +0 -6
- package/bundled/gateway/node_modules/http-errors/index.js +3 -4
- package/bundled/gateway/node_modules/http-errors/package.json +8 -12
- package/bundled/gateway/node_modules/qs/CHANGELOG.md +0 -16
- package/bundled/gateway/node_modules/qs/README.md +1 -1
- package/bundled/gateway/node_modules/qs/dist/qs.js +15 -15
- package/bundled/gateway/node_modules/qs/eslint.config.mjs +0 -1
- package/bundled/gateway/node_modules/qs/lib/parse.js +24 -54
- package/bundled/gateway/node_modules/qs/lib/stringify.js +4 -11
- package/bundled/gateway/node_modules/qs/package.json +3 -3
- package/bundled/gateway/node_modules/qs/test/parse.js +0 -135
- package/bundled/gateway/node_modules/qs/test/stringify.js +0 -138
- package/bundled/gateway/node_modules/qs/test/utils.js +3 -31
- package/bundled/gateway/node_modules/raw-body/HISTORY.md +308 -0
- package/bundled/gateway/node_modules/raw-body/SECURITY.md +24 -0
- package/bundled/gateway/node_modules/raw-body/package.json +7 -5
- package/bundled/gateway/node_modules/send/HISTORY.md +7 -19
- package/bundled/gateway/node_modules/send/node_modules/encodeurl/HISTORY.md +14 -0
- package/bundled/gateway/node_modules/send/node_modules/encodeurl/LICENSE +22 -0
- package/bundled/gateway/node_modules/send/node_modules/encodeurl/README.md +128 -0
- package/bundled/gateway/node_modules/send/node_modules/encodeurl/index.js +60 -0
- package/bundled/gateway/node_modules/send/node_modules/encodeurl/package.json +40 -0
- package/bundled/gateway/node_modules/send/package.json +6 -6
- package/bundled/gateway/node_modules/serve-static/HISTORY.md +0 -16
- package/bundled/gateway/node_modules/serve-static/node_modules/encodeurl/HISTORY.md +14 -0
- package/bundled/gateway/node_modules/serve-static/node_modules/encodeurl/LICENSE +22 -0
- package/bundled/gateway/node_modules/serve-static/node_modules/encodeurl/README.md +128 -0
- package/bundled/gateway/node_modules/serve-static/node_modules/encodeurl/index.js +60 -0
- package/bundled/gateway/node_modules/serve-static/node_modules/encodeurl/package.json +40 -0
- package/bundled/gateway/node_modules/serve-static/package.json +3 -3
- package/bundled/gateway/node_modules/statuses/HISTORY.md +0 -5
- package/bundled/gateway/node_modules/statuses/README.md +0 -3
- package/bundled/gateway/node_modules/statuses/package.json +7 -7
- package/bundled/gateway/package-lock.json +137 -88
- package/bundled/gateway/package.json +23 -5
- package/bundled/ollama/node_modules/.package-lock.json +104 -85
- package/bundled/ollama/node_modules/axios/CHANGELOG.md +0 -42
- package/bundled/ollama/node_modules/axios/README.md +237 -237
- package/bundled/ollama/node_modules/axios/dist/axios.js +21 -113
- package/bundled/ollama/node_modules/axios/dist/axios.js.map +1 -0
- package/bundled/ollama/node_modules/axios/dist/axios.min.js +2 -2
- package/bundled/ollama/node_modules/axios/dist/axios.min.js.map +1 -1
- package/bundled/ollama/node_modules/axios/dist/browser/axios.cjs +15 -121
- package/bundled/ollama/node_modules/axios/dist/browser/axios.cjs.map +1 -0
- package/bundled/ollama/node_modules/axios/dist/esm/axios.js +15 -121
- package/bundled/ollama/node_modules/axios/dist/esm/axios.js.map +1 -0
- package/bundled/ollama/node_modules/axios/dist/esm/axios.min.js +2 -2
- package/bundled/ollama/node_modules/axios/dist/esm/axios.min.js.map +1 -1
- package/bundled/ollama/node_modules/axios/dist/node/axios.cjs +107 -249
- package/bundled/ollama/node_modules/axios/dist/node/axios.cjs.map +1 -0
- package/bundled/ollama/node_modules/axios/index.d.cts +3 -8
- package/bundled/ollama/node_modules/axios/index.d.ts +1 -4
- package/bundled/ollama/node_modules/axios/lib/adapters/fetch.js +0 -79
- package/bundled/ollama/node_modules/axios/lib/adapters/http.js +118 -62
- package/bundled/ollama/node_modules/axios/lib/core/Axios.js +0 -1
- package/bundled/ollama/node_modules/axios/lib/core/AxiosHeaders.js +2 -2
- package/bundled/ollama/node_modules/axios/lib/defaults/transitional.js +0 -1
- package/bundled/ollama/node_modules/axios/lib/env/data.js +1 -1
- package/bundled/ollama/node_modules/axios/lib/helpers/buildURL.js +1 -1
- package/bundled/ollama/node_modules/axios/lib/helpers/formDataToStream.js +2 -2
- package/bundled/ollama/node_modules/axios/lib/helpers/resolveConfig.js +6 -12
- package/bundled/ollama/node_modules/axios/lib/helpers/toFormData.js +1 -1
- package/bundled/ollama/node_modules/axios/lib/utils.js +2 -23
- package/bundled/ollama/node_modules/axios/package.json +13 -29
- package/bundled/ollama/node_modules/body-parser/HISTORY.md +0 -14
- package/bundled/ollama/node_modules/body-parser/SECURITY.md +25 -0
- package/bundled/ollama/node_modules/body-parser/lib/types/json.js +5 -1
- package/bundled/ollama/node_modules/body-parser/lib/types/urlencoded.js +15 -7
- package/bundled/ollama/node_modules/body-parser/package.json +10 -9
- package/bundled/ollama/node_modules/cookie/index.js +35 -24
- package/bundled/ollama/node_modules/cookie/package.json +1 -1
- package/bundled/ollama/node_modules/cookie-signature/History.md +1 -5
- package/bundled/ollama/node_modules/cookie-signature/index.js +6 -6
- package/bundled/ollama/node_modules/cookie-signature/package.json +2 -2
- package/bundled/ollama/node_modules/express/History.md +0 -43
- package/bundled/ollama/node_modules/express/lib/response.js +0 -1
- package/bundled/ollama/node_modules/express/lib/utils.js +1 -2
- package/bundled/ollama/node_modules/express/package.json +17 -21
- package/bundled/ollama/node_modules/finalhandler/HISTORY.md +0 -21
- package/bundled/ollama/node_modules/finalhandler/README.md +2 -2
- package/bundled/ollama/node_modules/finalhandler/index.js +2 -7
- package/bundled/ollama/node_modules/finalhandler/node_modules/encodeurl/HISTORY.md +14 -0
- package/bundled/ollama/node_modules/finalhandler/node_modules/encodeurl/LICENSE +22 -0
- package/bundled/ollama/node_modules/finalhandler/node_modules/encodeurl/README.md +128 -0
- package/bundled/ollama/node_modules/finalhandler/node_modules/encodeurl/index.js +60 -0
- package/bundled/ollama/node_modules/finalhandler/node_modules/encodeurl/package.json +40 -0
- package/bundled/ollama/node_modules/finalhandler/package.json +9 -10
- package/bundled/ollama/node_modules/http-errors/HISTORY.md +0 -6
- package/bundled/ollama/node_modules/http-errors/index.js +3 -4
- package/bundled/ollama/node_modules/http-errors/package.json +8 -12
- package/bundled/ollama/node_modules/qs/CHANGELOG.md +0 -16
- package/bundled/ollama/node_modules/qs/README.md +1 -1
- package/bundled/ollama/node_modules/qs/dist/qs.js +15 -15
- package/bundled/ollama/node_modules/qs/eslint.config.mjs +0 -1
- package/bundled/ollama/node_modules/qs/lib/parse.js +24 -54
- package/bundled/ollama/node_modules/qs/lib/stringify.js +4 -11
- package/bundled/ollama/node_modules/qs/package.json +3 -3
- package/bundled/ollama/node_modules/qs/test/parse.js +0 -135
- package/bundled/ollama/node_modules/qs/test/stringify.js +0 -138
- package/bundled/ollama/node_modules/qs/test/utils.js +3 -31
- package/bundled/ollama/node_modules/raw-body/HISTORY.md +308 -0
- package/bundled/ollama/node_modules/raw-body/SECURITY.md +24 -0
- package/bundled/ollama/node_modules/raw-body/package.json +7 -5
- package/bundled/ollama/node_modules/send/HISTORY.md +7 -19
- package/bundled/ollama/node_modules/send/node_modules/encodeurl/HISTORY.md +14 -0
- package/bundled/ollama/node_modules/send/node_modules/encodeurl/LICENSE +22 -0
- package/bundled/ollama/node_modules/send/node_modules/encodeurl/README.md +128 -0
- package/bundled/ollama/node_modules/send/node_modules/encodeurl/index.js +60 -0
- package/bundled/ollama/node_modules/send/node_modules/encodeurl/package.json +40 -0
- package/bundled/ollama/node_modules/send/package.json +6 -6
- package/bundled/ollama/node_modules/serve-static/HISTORY.md +0 -16
- package/bundled/ollama/node_modules/serve-static/node_modules/encodeurl/HISTORY.md +14 -0
- package/bundled/ollama/node_modules/serve-static/node_modules/encodeurl/LICENSE +22 -0
- package/bundled/ollama/node_modules/serve-static/node_modules/encodeurl/README.md +128 -0
- package/bundled/ollama/node_modules/serve-static/node_modules/encodeurl/index.js +60 -0
- package/bundled/ollama/node_modules/serve-static/node_modules/encodeurl/package.json +40 -0
- package/bundled/ollama/node_modules/serve-static/package.json +3 -3
- package/bundled/ollama/node_modules/statuses/HISTORY.md +0 -5
- package/bundled/ollama/node_modules/statuses/README.md +0 -3
- package/bundled/ollama/node_modules/statuses/package.json +7 -7
- package/bundled/ollama/package-lock.json +107 -88
- package/bundled/ollama/package.json +24 -4
- package/node_modules/@sap-llm-gateway/service-key-parser/package.json +1 -1
- package/package.json +2 -2
- package/bundled/gateway/node_modules/axios/lib/helpers/Http2Sessions.js +0 -119
- package/bundled/ollama/node_modules/axios/lib/helpers/Http2Sessions.js +0 -119
|
@@ -29,10 +29,27 @@
|
|
|
29
29
|
</td>
|
|
30
30
|
<td align="center" width="50%">
|
|
31
31
|
<a
|
|
32
|
-
href="https://
|
|
32
|
+
href="https://hopper.security/?utm_source=axios&utm_medium=readme_sponsorlist&utm_campaign=sponsorship"
|
|
33
|
+
style="padding: 10px; display: inline-block"
|
|
33
34
|
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>
|
|
36
53
|
</td>
|
|
37
54
|
</tr>
|
|
38
55
|
</table>
|
|
@@ -125,7 +142,7 @@
|
|
|
125
142
|
</a>
|
|
126
143
|
<p
|
|
127
144
|
align="center"
|
|
128
|
-
title="Hi, we're Descope! We are building something in the authentication space for app developers and can
|
|
145
|
+
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."
|
|
129
146
|
>
|
|
130
147
|
Reduce user friction, prevent account takeover, and get a 360° view of your customer and agentic identities with the Descope External IAM platform.
|
|
131
148
|
</p>
|
|
@@ -233,7 +250,7 @@
|
|
|
233
250
|
<p
|
|
234
251
|
align="center"
|
|
235
252
|
>
|
|
236
|
-
At Buzzoid, you can buy Instagram followers
|
|
253
|
+
At Buzzoid, you can buy Instagram followers quickly, safely, and easily with just a few clicks. Rated world's #1 IG service since 2012.
|
|
237
254
|
</p>
|
|
238
255
|
<p align="center">
|
|
239
256
|
<a
|
|
@@ -271,29 +288,10 @@
|
|
|
271
288
|
</td>
|
|
272
289
|
<td align="center" width="33.333333333333336%">
|
|
273
290
|
<a
|
|
274
|
-
href="https://
|
|
275
|
-
style="padding: 10px; display: inline-block"
|
|
291
|
+
href="https://opencollective.com/axios/contribute"
|
|
276
292
|
target="_blank"
|
|
293
|
+
>💜 Become a sponsor</a
|
|
277
294
|
>
|
|
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>
|
|
297
295
|
</td>
|
|
298
296
|
</tr>
|
|
299
297
|
</table>
|
|
@@ -317,61 +315,62 @@
|
|
|
317
315
|
<div align="center">
|
|
318
316
|
|
|
319
317
|
[](https://www.npmjs.org/package/axios)
|
|
318
|
+
[](https://cdnjs.com/libraries/axios)
|
|
320
319
|
[](https://github.com/axios/axios/actions/workflows/ci.yml)
|
|
321
320
|
[](https://gitpod.io/#https://github.com/axios/axios)
|
|
321
|
+
[](https://coveralls.io/r/mzabriskie/axios)
|
|
322
322
|
[](https://packagephobia.now.sh/result?p=axios)
|
|
323
323
|
[](https://bundlephobia.com/package/axios@latest)
|
|
324
324
|
[](https://npm-stat.com/charts.html?package=axios)
|
|
325
325
|
[](https://gitter.im/mzabriskie/axios)
|
|
326
326
|
[](https://www.codetriage.com/axios/axios)
|
|
327
327
|
[](CONTRIBUTORS.md)
|
|
328
|
-
[](https://agentfriendlycode.com/repo/32)
|
|
329
328
|
|
|
330
329
|
</div>
|
|
331
330
|
|
|
332
|
-
## Table of
|
|
331
|
+
## Table of Contents
|
|
333
332
|
|
|
334
333
|
- [Features](#features)
|
|
335
|
-
- [Browser
|
|
334
|
+
- [Browser Support](#browser-support)
|
|
336
335
|
- [Installing](#installing)
|
|
337
336
|
- [Package manager](#package-manager)
|
|
338
337
|
- [CDN](#cdn)
|
|
339
338
|
- [Example](#example)
|
|
340
339
|
- [Axios API](#axios-api)
|
|
341
340
|
- [Request method aliases](#request-method-aliases)
|
|
342
|
-
- [Concurrency](#concurrency-deprecated)
|
|
341
|
+
- [Concurrency 👎](#concurrency-deprecated)
|
|
343
342
|
- [Creating an instance](#creating-an-instance)
|
|
344
343
|
- [Instance methods](#instance-methods)
|
|
345
|
-
- [Request
|
|
346
|
-
- [Response
|
|
347
|
-
- [Config
|
|
344
|
+
- [Request Config](#request-config)
|
|
345
|
+
- [Response Schema](#response-schema)
|
|
346
|
+
- [Config Defaults](#config-defaults)
|
|
348
347
|
- [Global axios defaults](#global-axios-defaults)
|
|
349
348
|
- [Custom instance defaults](#custom-instance-defaults)
|
|
350
349
|
- [Config order of precedence](#config-order-of-precedence)
|
|
351
350
|
- [Interceptors](#interceptors)
|
|
352
|
-
- [Multiple
|
|
353
|
-
- [Handling
|
|
354
|
-
- [Handling
|
|
351
|
+
- [Multiple Interceptors](#multiple-interceptors)
|
|
352
|
+
- [Handling Errors](#handling-errors)
|
|
353
|
+
- [Handling Timeouts](#handling-timeouts)
|
|
355
354
|
- [Cancellation](#cancellation)
|
|
356
355
|
- [AbortController](#abortcontroller)
|
|
357
|
-
- [CancelToken](#canceltoken-deprecated)
|
|
356
|
+
- [CancelToken 👎](#canceltoken-deprecated)
|
|
358
357
|
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
|
|
359
358
|
- [URLSearchParams](#urlsearchparams)
|
|
360
359
|
- [Query string](#query-string-older-browsers)
|
|
361
|
-
- [Automatic serialization](
|
|
360
|
+
- [🆕 Automatic serialization](#-automatic-serialization-to-urlsearchparams)
|
|
362
361
|
- [Using multipart/form-data format](#using-multipartform-data-format)
|
|
363
362
|
- [FormData](#formdata)
|
|
364
|
-
- [Automatic serialization](
|
|
365
|
-
- [Posting
|
|
366
|
-
- [HTML
|
|
367
|
-
- [Progress capturing](
|
|
368
|
-
- [Rate limiting](
|
|
369
|
-
- [AxiosHeaders](
|
|
370
|
-
- [Fetch adapter](
|
|
371
|
-
- [Custom fetch](
|
|
372
|
-
- [Using with Tauri](
|
|
373
|
-
- [Using with SvelteKit](
|
|
374
|
-
- [
|
|
363
|
+
- [🆕 Automatic serialization](#-automatic-serialization-to-formdata)
|
|
364
|
+
- [Files Posting](#files-posting)
|
|
365
|
+
- [HTML Form Posting](#-html-form-posting-browser)
|
|
366
|
+
- [🆕 Progress capturing](#-progress-capturing)
|
|
367
|
+
- [🆕 Rate limiting](#-rate-limiting)
|
|
368
|
+
- [🆕 AxiosHeaders](#-axiosheaders)
|
|
369
|
+
- [🔥 Fetch adapter](#-fetch-adapter)
|
|
370
|
+
- [🔥 Custom fetch](#-custom-fetch)
|
|
371
|
+
- [🔥 Using with Tauri](#-using-with-tauri)
|
|
372
|
+
- [🔥 Using with SvelteKit](#-using-with-sveltekit)
|
|
373
|
+
- [🔥 HTTP2](#-http2)
|
|
375
374
|
- [Semver](#semver)
|
|
376
375
|
- [Promises](#promises)
|
|
377
376
|
- [TypeScript](#typescript)
|
|
@@ -383,17 +382,17 @@
|
|
|
383
382
|
|
|
384
383
|
## Features
|
|
385
384
|
|
|
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
|
-
-
|
|
389
|
-
- Intercept requests and responses to add custom logic or transform data.
|
|
390
|
-
- Transform request and response data.
|
|
391
|
-
- Cancel requests
|
|
392
|
-
-
|
|
393
|
-
-
|
|
394
|
-
-
|
|
385
|
+
- **Browser Requests:** Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) directly from the browser.
|
|
386
|
+
- **Node.js Requests:** Make [http](https://nodejs.org/api/http.html) requests from Node.js environments.
|
|
387
|
+
- **Promise-based:** Fully supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API for easier asynchronous code.
|
|
388
|
+
- **Interceptors:** Intercept requests and responses to add custom logic or transform data.
|
|
389
|
+
- **Data Transformation:** Transform request and response data automatically.
|
|
390
|
+
- **Request Cancellation:** Cancel requests using built-in mechanisms.
|
|
391
|
+
- **Automatic JSON Handling:** Automatically serializes and parses [JSON](https://www.json.org/json-en.html) data.
|
|
392
|
+
- **Form Serialization:** 🆕 Automatically serializes data objects to `multipart/form-data` or `x-www-form-urlencoded` formats.
|
|
393
|
+
- **XSRF Protection:** Client-side support to protect against [Cross-Site Request Forgery](https://en.wikipedia.org/wiki/Cross-site_request_forgery).
|
|
395
394
|
|
|
396
|
-
## Browser
|
|
395
|
+
## Browser Support
|
|
397
396
|
|
|
398
397
|
| Chrome | Firefox | Safari | Opera | Edge |
|
|
399
398
|
| :------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------: |
|
|
@@ -430,7 +429,7 @@ Using bun:
|
|
|
430
429
|
$ bun add axios
|
|
431
430
|
```
|
|
432
431
|
|
|
433
|
-
Once the package is installed, import
|
|
432
|
+
Once the package is installed, you can import the library using `import` or `require` approach:
|
|
434
433
|
|
|
435
434
|
```js
|
|
436
435
|
import axios, { isCancel, AxiosError } from 'axios';
|
|
@@ -452,13 +451,14 @@ const axios = require('axios');
|
|
|
452
451
|
console.log(axios.isCancel('something'));
|
|
453
452
|
```
|
|
454
453
|
|
|
455
|
-
|
|
454
|
+
For some bundlers and some ES6 linters you may need to do the following:
|
|
456
455
|
|
|
457
456
|
```js
|
|
458
457
|
import { default as axios } from 'axios';
|
|
459
458
|
```
|
|
460
459
|
|
|
461
|
-
|
|
460
|
+
For cases where something went wrong when trying to import a module into a custom or legacy environment,
|
|
461
|
+
you can try importing the module package directly:
|
|
462
462
|
|
|
463
463
|
```js
|
|
464
464
|
const axios = require('axios/dist/browser/axios.cjs'); // browser commonJS bundle (ES2017)
|
|
@@ -498,7 +498,7 @@ axios
|
|
|
498
498
|
params: {
|
|
499
499
|
ID: 12345,
|
|
500
500
|
},
|
|
501
|
-
timeout: 5000, // 5 seconds
|
|
501
|
+
timeout: 5000, // 5 seconds — see "Handling Timeouts" below for matching error handling
|
|
502
502
|
})
|
|
503
503
|
.then(function (response) {
|
|
504
504
|
console.log(response);
|
|
@@ -529,10 +529,10 @@ console.log(response);
|
|
|
529
529
|
}
|
|
530
530
|
```
|
|
531
531
|
|
|
532
|
-
> Note
|
|
532
|
+
> **Note**: Set a `timeout` in production — without one, a stalled request can hang
|
|
533
533
|
> indefinitely. See [Handling Timeouts](#handling-timeouts) for the matching error handling.
|
|
534
534
|
|
|
535
|
-
> Note
|
|
535
|
+
> **Note**: `async/await` is part of ECMAScript 2017 and is not supported in Internet
|
|
536
536
|
> Explorer and older browsers, so use with caution.
|
|
537
537
|
|
|
538
538
|
Performing a `POST` request
|
|
@@ -617,13 +617,13 @@ For convenience, aliases have been provided for all common request methods.
|
|
|
617
617
|
|
|
618
618
|
##### axios.patch(url[, data[, config]])
|
|
619
619
|
|
|
620
|
-
######
|
|
620
|
+
###### NOTE
|
|
621
621
|
|
|
622
622
|
When using the alias methods `url`, `method`, and `data` properties don't need to be specified in config.
|
|
623
623
|
|
|
624
|
-
### Concurrency (
|
|
624
|
+
### Concurrency (Deprecated)
|
|
625
625
|
|
|
626
|
-
|
|
626
|
+
Please use `Promise.all` to replace the below functions.
|
|
627
627
|
|
|
628
628
|
Helper functions for dealing with concurrent requests.
|
|
629
629
|
|
|
@@ -646,7 +646,7 @@ const instance = axios.create({
|
|
|
646
646
|
|
|
647
647
|
### Instance methods
|
|
648
648
|
|
|
649
|
-
The
|
|
649
|
+
The available instance methods are listed below. The specified config will be merged with the instance config.
|
|
650
650
|
|
|
651
651
|
##### axios#request(config)
|
|
652
652
|
|
|
@@ -666,11 +666,11 @@ The following instance methods are available. Axios merges the specified config
|
|
|
666
666
|
|
|
667
667
|
##### axios#getUri([config])
|
|
668
668
|
|
|
669
|
-
## Request
|
|
669
|
+
## Request Config
|
|
670
670
|
|
|
671
|
-
### Security notice: decompression-bomb protection is opt-in
|
|
671
|
+
### ⚠️ Security notice: decompression-bomb protection is opt-in
|
|
672
672
|
|
|
673
|
-
By default `maxContentLength` and `maxBodyLength` are `-1` (unlimited). A malicious or compromised server can return a tiny gzip/deflate/brotli
|
|
673
|
+
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.
|
|
674
674
|
|
|
675
675
|
If you call servers you do not fully trust, **set a cap**:
|
|
676
676
|
|
|
@@ -681,17 +681,17 @@ axios.defaults.maxBodyLength = 10 * 1024 * 1024;
|
|
|
681
681
|
|
|
682
682
|
See the [security guide](https://axios.rest/pages/misc/security.html) for details.
|
|
683
683
|
|
|
684
|
-
These config options
|
|
684
|
+
These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified.
|
|
685
685
|
|
|
686
686
|
```js
|
|
687
687
|
{
|
|
688
|
-
// `url` is the server URL for the request
|
|
688
|
+
// `url` is the server URL that will be used for the request
|
|
689
689
|
url: '/user',
|
|
690
690
|
|
|
691
691
|
// `method` is the request method to be used when making the request
|
|
692
692
|
method: 'get', // default
|
|
693
693
|
|
|
694
|
-
//
|
|
694
|
+
// `baseURL` will be prepended to `url` unless `url` is absolute and the option `allowAbsoluteUrls` is set to true.
|
|
695
695
|
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
|
|
696
696
|
// to the methods of that instance.
|
|
697
697
|
baseURL: 'https://some-domain.com/api/',
|
|
@@ -720,7 +720,7 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
720
720
|
return data;
|
|
721
721
|
}],
|
|
722
722
|
|
|
723
|
-
// `parseReviver` is an optional function passed as the
|
|
723
|
+
// `parseReviver` is an optional function that will be passed as the
|
|
724
724
|
// second argument (reviver) to JSON.parse()
|
|
725
725
|
parseReviver: function (key, value, context) {
|
|
726
726
|
// In modern environments, context.source provides the raw JSON string
|
|
@@ -789,7 +789,7 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
789
789
|
data: 'Country=Brasil&City=Belo Horizonte',
|
|
790
790
|
|
|
791
791
|
// `timeout` specifies the number of milliseconds before the request times out.
|
|
792
|
-
// If the request takes longer than `timeout`,
|
|
792
|
+
// If the request takes longer than `timeout`, the request will be aborted.
|
|
793
793
|
timeout: 1000, // default is `0` (no timeout)
|
|
794
794
|
|
|
795
795
|
// `withCredentials` indicates whether or not cross-site Access-Control requests
|
|
@@ -810,12 +810,6 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
810
810
|
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
|
|
811
811
|
// This will set an `Authorization` header, overwriting any existing
|
|
812
812
|
// `Authorization` custom headers you have set using `headers`.
|
|
813
|
-
// If `auth` is omitted, the Node.js HTTP and fetch adapters can read
|
|
814
|
-
// HTTP Basic auth credentials from the request URL, for example
|
|
815
|
-
// `https://user:pass@example.com`. Axios decodes percent-encoded URL
|
|
816
|
-
// credentials, and `auth` takes precedence over URL-embedded credentials.
|
|
817
|
-
// The Node.js HTTP adapter preserves Basic auth on same-origin redirects
|
|
818
|
-
// and strips it on cross-origin redirects.
|
|
819
813
|
// Please note that only HTTP Basic auth is configurable through this parameter.
|
|
820
814
|
// For Bearer tokens and such, use `Authorization` custom headers instead.
|
|
821
815
|
auth: {
|
|
@@ -889,16 +883,17 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
889
883
|
|
|
890
884
|
// `validateStatus` defines whether to resolve or reject the promise for a given
|
|
891
885
|
// HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
|
|
892
|
-
// or `undefined`),
|
|
886
|
+
// or `undefined`), the promise will be resolved; otherwise, the promise will be
|
|
887
|
+
// rejected.
|
|
893
888
|
validateStatus: function (status) {
|
|
894
889
|
return status >= 200 && status < 300; // default
|
|
895
890
|
},
|
|
896
891
|
|
|
897
892
|
// `maxRedirects` defines the maximum number of redirects to follow in node.js.
|
|
898
|
-
// If set to 0,
|
|
893
|
+
// If set to 0, no redirects will be followed.
|
|
899
894
|
maxRedirects: 21, // default
|
|
900
895
|
|
|
901
|
-
// `beforeRedirect` defines a function that
|
|
896
|
+
// `beforeRedirect` defines a function that will be called before redirect.
|
|
902
897
|
// Use this to adjust the request options upon redirecting,
|
|
903
898
|
// to inspect the latest response headers,
|
|
904
899
|
// or to cancel the request by throwing an error
|
|
@@ -914,10 +909,16 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
914
909
|
},
|
|
915
910
|
// Security note:
|
|
916
911
|
// The `beforeRedirect` hook runs after sensitive headers are stripped during redirects.
|
|
917
|
-
// `follow-redirects` removes credentials on protocol
|
|
918
|
-
//
|
|
919
|
-
//
|
|
920
|
-
|
|
912
|
+
//The `follow-redirects` library removes credentials on protocol downgrade (HTTPS → HTTP) for security.
|
|
913
|
+
//Since `beforeRedirect` runs after this, re-injecting credentials without checking the protocol can expose sensitive data.
|
|
914
|
+
//Always ensure credentials are only added for trusted HTTPS destinations.
|
|
915
|
+
|
|
916
|
+
// Security note:
|
|
917
|
+
// The beforeRedirect hook runs after sensitive headers are stripped during redirects.
|
|
918
|
+
// Re-injecting credentials without checking the destination can expose sensitive data.
|
|
919
|
+
// Only add credentials for trusted HTTPS destinations.
|
|
920
|
+
// Avoid re-adding credentials on downgraded redirects.
|
|
921
|
+
|
|
921
922
|
|
|
922
923
|
// `socketPath` defines a UNIX Socket to be used in node.js.
|
|
923
924
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
|
|
@@ -936,10 +937,10 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
936
937
|
// `ERR_BAD_OPTION_VALUE`. When null/undefined, no restriction is applied.
|
|
937
938
|
allowedSocketPaths: null, // default
|
|
938
939
|
|
|
939
|
-
// `transport` determines the transport method
|
|
940
|
-
// If defined,
|
|
941
|
-
//
|
|
942
|
-
// Otherwise,
|
|
940
|
+
// `transport` determines the transport method that will be used to make the request.
|
|
941
|
+
// If defined, it will be used. Otherwise, if `maxRedirects` is 0,
|
|
942
|
+
// the default `http` or `https` library will be used, depending on the protocol specified in `protocol`.
|
|
943
|
+
// Otherwise, the `httpFollow` or `httpsFollow` library will be used, again depending on the protocol,
|
|
943
944
|
// which can handle redirects.
|
|
944
945
|
transport: undefined, // default
|
|
945
946
|
|
|
@@ -965,15 +966,12 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
965
966
|
// For `https://` targets, axios establishes a CONNECT tunnel through the
|
|
966
967
|
// proxy and performs TLS end-to-end with the origin; `Proxy-Authorization`
|
|
967
968
|
// is sent on the CONNECT request only, never on the wrapped TLS request,
|
|
968
|
-
// so the proxy never sees the URL, headers, or body.
|
|
969
|
-
// `httpsAgent`
|
|
970
|
-
// `rejectUnauthorized` to the generated tunneling agent, so they still apply
|
|
971
|
-
// to the origin TLS connection.
|
|
972
|
-
// If you supply an `HttpsProxyAgent`, axios leaves tunneling to that agent.
|
|
969
|
+
// so the proxy never sees the URL, headers, or body. Supply a custom
|
|
970
|
+
// `httpsAgent` to opt out of automatic CONNECT tunneling.
|
|
973
971
|
// If the proxy server uses HTTPS, then you must set the protocol to `https`.
|
|
974
972
|
// A user-supplied `Host` header in `headers` is preserved when forwarding
|
|
975
973
|
// through a proxy (case-insensitive match on `host`/`Host`/`HOST`); this
|
|
976
|
-
// lets you target a virtual host that differs from the request URL
|
|
974
|
+
// lets you target a virtual host that differs from the request URL — for
|
|
977
975
|
// example, hitting `127.0.0.1:4000` while having the proxy treat the
|
|
978
976
|
// request as `example.com`. If no `Host` header is supplied, axios
|
|
979
977
|
// defaults it to the request URL's `hostname:port` as before. The Host
|
|
@@ -1002,8 +1000,6 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
1002
1000
|
// `decompress` indicates whether or not the response body should be decompressed
|
|
1003
1001
|
// automatically. If set to `true` will also remove the 'content-encoding' header
|
|
1004
1002
|
// from the responses objects of all decompressed responses
|
|
1005
|
-
// Axios supports gzip, deflate, brotli, and zstd when the current Node.js
|
|
1006
|
-
// runtime provides the corresponding zlib decompressor.
|
|
1007
1003
|
// - Node only (XHR cannot turn off decompression)
|
|
1008
1004
|
decompress: true, // default
|
|
1009
1005
|
|
|
@@ -1033,11 +1029,6 @@ These config options are available for requests. Only `url` is required. Request
|
|
|
1033
1029
|
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
|
1034
1030
|
clarifyTimeoutError: false,
|
|
1035
1031
|
|
|
1036
|
-
// advertise `zstd` in the default Accept-Encoding header when the current
|
|
1037
|
-
// Node.js runtime supports zstd decompression. Axios still decompresses
|
|
1038
|
-
// zstd responses when support exists and `decompress` is true.
|
|
1039
|
-
advertiseZstdAcceptEncoding: false,
|
|
1040
|
-
|
|
1041
1032
|
// use the legacy interceptor request/response ordering
|
|
1042
1033
|
legacyInterceptorReqResOrdering: true, // default
|
|
1043
1034
|
},
|
|
@@ -1082,17 +1073,17 @@ const client = axios.create({
|
|
|
1082
1073
|
});
|
|
1083
1074
|
```
|
|
1084
1075
|
|
|
1085
|
-
## HTTP/2
|
|
1076
|
+
## 🔥 HTTP/2 Support
|
|
1086
1077
|
|
|
1087
|
-
Axios has experimental HTTP/2 support
|
|
1078
|
+
Axios has experimental HTTP/2 support available via the Node.js HTTP adapter.
|
|
1088
1079
|
|
|
1089
|
-
Support depends on the runtime environment and Node.js version.
|
|
1080
|
+
Support depends on the runtime environment and Node.js version. Features like redirects and some behaviors may not be fully supported with HTTP/2.
|
|
1090
1081
|
|
|
1091
|
-
Options like `httpVersion` and `http2Options` are adapter-specific and may not work
|
|
1082
|
+
Options like `httpVersion` and `http2Options` are adapter-specific and may not work consistently across all environments.
|
|
1092
1083
|
|
|
1093
|
-
If
|
|
1084
|
+
If HTTP/2 functionality is required, ensure your runtime environment supports it or consider using alternative libraries or custom adapters.
|
|
1094
1085
|
|
|
1095
|
-
## Response
|
|
1086
|
+
## Response Schema
|
|
1096
1087
|
|
|
1097
1088
|
The response to a request contains the following information.
|
|
1098
1089
|
|
|
@@ -1122,7 +1113,7 @@ The response to a request contains the following information.
|
|
|
1122
1113
|
}
|
|
1123
1114
|
```
|
|
1124
1115
|
|
|
1125
|
-
When using `then`, you receive the response
|
|
1116
|
+
When using `then`, you will receive the response as follows:
|
|
1126
1117
|
|
|
1127
1118
|
```js
|
|
1128
1119
|
const response = await axios.get('/user/12345');
|
|
@@ -1133,18 +1124,18 @@ console.log(response.headers);
|
|
|
1133
1124
|
console.log(response.config);
|
|
1134
1125
|
```
|
|
1135
1126
|
|
|
1136
|
-
When using `catch`, or passing a [rejection callback](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) as
|
|
1127
|
+
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 will be available through the `error` object as explained in the [Handling Errors](#handling-errors) section.
|
|
1137
1128
|
|
|
1138
|
-
## Config
|
|
1129
|
+
## Config Defaults
|
|
1139
1130
|
|
|
1140
|
-
|
|
1131
|
+
You can specify config defaults that will be applied to every request.
|
|
1141
1132
|
|
|
1142
1133
|
### Global axios defaults
|
|
1143
1134
|
|
|
1144
1135
|
```js
|
|
1145
1136
|
axios.defaults.baseURL = 'https://api.example.com';
|
|
1146
1137
|
|
|
1147
|
-
// Important: If
|
|
1138
|
+
// Important: If axios is used with multiple domains, the AUTH_TOKEN will be sent to all of them.
|
|
1148
1139
|
// See below for an example using Custom instance defaults instead.
|
|
1149
1140
|
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
1150
1141
|
|
|
@@ -1165,7 +1156,7 @@ instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
|
1165
1156
|
|
|
1166
1157
|
### Config order of precedence
|
|
1167
1158
|
|
|
1168
|
-
|
|
1159
|
+
Config will be merged with an order of precedence. The order is library defaults found in [lib/defaults/index.js](https://github.com/axios/axios/blob/main/lib/defaults/index.js#L49), 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.
|
|
1169
1160
|
|
|
1170
1161
|
```js
|
|
1171
1162
|
// Create an instance using the config defaults provided by the library
|
|
@@ -1267,8 +1258,8 @@ axios.interceptors.request.use(
|
|
|
1267
1258
|
```
|
|
1268
1259
|
|
|
1269
1260
|
If you want to execute a particular interceptor based on a runtime check,
|
|
1270
|
-
you can add a `runWhen` function to the options object. The request interceptor will not
|
|
1271
|
-
of `runWhen` is `false`.
|
|
1261
|
+
you can add a `runWhen` function to the options object. The request interceptor will not be executed **if and only if** the return
|
|
1262
|
+
of `runWhen` is `false`. The function will be called with the config
|
|
1272
1263
|
object (don't forget that you can bind your own arguments to it as well.) This can be handy when you have an
|
|
1273
1264
|
asynchronous request interceptor that only needs to run at certain times.
|
|
1274
1265
|
|
|
@@ -1286,15 +1277,15 @@ axios.interceptors.request.use(
|
|
|
1286
1277
|
);
|
|
1287
1278
|
```
|
|
1288
1279
|
|
|
1289
|
-
> Note
|
|
1280
|
+
> **Note:** The options parameter(having `synchronous` and `runWhen` properties) is only supported for request interceptors at the moment.
|
|
1290
1281
|
|
|
1291
|
-
### Interceptor
|
|
1282
|
+
### Interceptor Execution Order
|
|
1292
1283
|
|
|
1293
|
-
|
|
1284
|
+
**Important:** Interceptors have different execution orders depending on their type!
|
|
1294
1285
|
|
|
1295
|
-
Request interceptors
|
|
1286
|
+
Request interceptors are executed in **reverse order** (LIFO - Last In, First Out). This means the _last_ interceptor added is executed **first**.
|
|
1296
1287
|
|
|
1297
|
-
Response interceptors
|
|
1288
|
+
Response interceptors are executed in the **order they were added** (FIFO - First In, First Out). This means the _first_ interceptor added is executed **first**.
|
|
1298
1289
|
|
|
1299
1290
|
Example:
|
|
1300
1291
|
|
|
@@ -1323,33 +1314,37 @@ instance.interceptors.response.use(interceptor('Response Interceptor 3'));
|
|
|
1323
1314
|
// Response Interceptor 3
|
|
1324
1315
|
```
|
|
1325
1316
|
|
|
1326
|
-
### Multiple
|
|
1317
|
+
### Multiple Interceptors
|
|
1327
1318
|
|
|
1328
|
-
|
|
1319
|
+
Given that you add multiple response interceptors
|
|
1320
|
+
and when the response was fulfilled
|
|
1329
1321
|
|
|
1330
|
-
-
|
|
1331
|
-
-
|
|
1332
|
-
-
|
|
1333
|
-
-
|
|
1334
|
-
-
|
|
1322
|
+
- then each interceptor is executed
|
|
1323
|
+
- then they are executed in the order they were added
|
|
1324
|
+
- then only the last interceptor's result is returned
|
|
1325
|
+
- then every interceptor receives the result of its predecessor
|
|
1326
|
+
- and when the fulfillment-interceptor throws
|
|
1327
|
+
- then the following fulfillment-interceptor is not called
|
|
1328
|
+
- then the following rejection-interceptor is called
|
|
1329
|
+
- once caught, another following fulfill-interceptor is called again (just like in a promise chain).
|
|
1335
1330
|
|
|
1336
1331
|
Read [the interceptor tests](./test/specs/interceptors.spec.js) to see all this in code.
|
|
1337
1332
|
|
|
1338
|
-
## Error
|
|
1333
|
+
## Error Types
|
|
1339
1334
|
|
|
1340
|
-
|
|
1335
|
+
There are many different axios error messages that can appear which can provide basic information about the specifics of the error and where opportunities may lie in debugging.
|
|
1341
1336
|
|
|
1342
|
-
|
|
1337
|
+
The general structure of axios errors is as follows:
|
|
1343
1338
|
| Property | Definition |
|
|
1344
1339
|
| -------- | ---------- |
|
|
1345
1340
|
| message | A quick summary of the error message and the status it failed with. |
|
|
1346
1341
|
| name | This defines where the error originated from. For axios, it will always be an 'AxiosError'. |
|
|
1347
|
-
| stack |
|
|
1342
|
+
| stack | Provides the stack trace of the error. |
|
|
1348
1343
|
| config | An axios config object with specific instance configurations defined by the user from when the request was made |
|
|
1349
|
-
| code |
|
|
1344
|
+
| code | Represents an axios identified error. The table below lists specific definitions for internal axios error. |
|
|
1350
1345
|
| status | HTTP response status code. See [here](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) for common HTTP response status code meanings.
|
|
1351
1346
|
|
|
1352
|
-
|
|
1347
|
+
Below is a list of potential axios identified error:
|
|
1353
1348
|
|
|
1354
1349
|
| Code | Definition |
|
|
1355
1350
|
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -1359,16 +1354,16 @@ These are the internal Axios error codes:
|
|
|
1359
1354
|
| ERR_DEPRECATED | Deprecated feature or method used in axios. |
|
|
1360
1355
|
| ERR_INVALID_URL | Invalid URL provided for axios request. |
|
|
1361
1356
|
| ECONNABORTED | Typically indicates that the request has been timed out (unless `transitional.clarifyTimeoutError` is set) or aborted by the browser or its plugin. |
|
|
1362
|
-
| ERR_CANCELED |
|
|
1363
|
-
| ETIMEDOUT | Request timed out
|
|
1357
|
+
| ERR_CANCELED | Feature or method is canceled explicitly by the user using an AbortSignal (or a CancelToken). |
|
|
1358
|
+
| ETIMEDOUT | Request timed out due to exceeding the default axios timelimit. `transitional.clarifyTimeoutError` must be set to `true`, otherwise a generic `ECONNABORTED` error will be thrown instead. |
|
|
1364
1359
|
| 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. |
|
|
1365
|
-
| ERR_FR_TOO_MANY_REDIRECTS | Request
|
|
1360
|
+
| ERR_FR_TOO_MANY_REDIRECTS | Request is redirected too many times; exceeds max redirects specified in axios configuration. |
|
|
1366
1361
|
| ERR_BAD_RESPONSE | Response cannot be parsed properly or is in an unexpected format. Usually related to a response with `5xx` status code. |
|
|
1367
1362
|
| ERR_BAD_REQUEST | The request has an unexpected format or is missing required parameters. Usually related to a response with `4xx` status code. |
|
|
1368
1363
|
|
|
1369
|
-
## Handling
|
|
1364
|
+
## Handling Errors
|
|
1370
1365
|
|
|
1371
|
-
|
|
1366
|
+
The default behavior is to reject every response that returns with a status code that falls out of the range of 2xx and treat it as an error.
|
|
1372
1367
|
|
|
1373
1368
|
```js
|
|
1374
1369
|
axios.get('/user/12345').catch(function (error) {
|
|
@@ -1391,7 +1386,7 @@ axios.get('/user/12345').catch(function (error) {
|
|
|
1391
1386
|
});
|
|
1392
1387
|
```
|
|
1393
1388
|
|
|
1394
|
-
|
|
1389
|
+
Using the `validateStatus` config option, you can override the default condition (status >= 200 && status < 300) and define HTTP code(s) that should throw an error.
|
|
1395
1390
|
|
|
1396
1391
|
```js
|
|
1397
1392
|
axios.get('/user/12345', {
|
|
@@ -1401,7 +1396,7 @@ axios.get('/user/12345', {
|
|
|
1401
1396
|
});
|
|
1402
1397
|
```
|
|
1403
1398
|
|
|
1404
|
-
|
|
1399
|
+
Using `toJSON` you get an object with more information about the HTTP error.
|
|
1405
1400
|
|
|
1406
1401
|
```js
|
|
1407
1402
|
axios.get('/user/12345').catch(function (error) {
|
|
@@ -1420,7 +1415,7 @@ axios.get('/user/12345', {
|
|
|
1420
1415
|
});
|
|
1421
1416
|
```
|
|
1422
1417
|
|
|
1423
|
-
## Handling
|
|
1418
|
+
## Handling Timeouts
|
|
1424
1419
|
|
|
1425
1420
|
```js
|
|
1426
1421
|
async function fetchWithTimeout() {
|
|
@@ -1454,7 +1449,7 @@ async function fetchWithTimeout() {
|
|
|
1454
1449
|
|
|
1455
1450
|
### AbortController
|
|
1456
1451
|
|
|
1457
|
-
|
|
1452
|
+
Starting from `v0.22.0` Axios supports AbortController to cancel requests in a fetch API way:
|
|
1458
1453
|
|
|
1459
1454
|
```js
|
|
1460
1455
|
const controller = new AbortController();
|
|
@@ -1470,15 +1465,15 @@ axios
|
|
|
1470
1465
|
controller.abort();
|
|
1471
1466
|
```
|
|
1472
1467
|
|
|
1473
|
-
### CancelToken
|
|
1468
|
+
### CancelToken `👎deprecated`
|
|
1474
1469
|
|
|
1475
1470
|
You can also cancel a request using a _CancelToken_.
|
|
1476
1471
|
|
|
1477
1472
|
> The axios cancel token API is based on the withdrawn [cancellable promises proposal](https://github.com/tc39/proposal-cancelable-promises).
|
|
1478
1473
|
|
|
1479
|
-
> This API is deprecated since v0.22.0 and
|
|
1474
|
+
> This API is deprecated since v0.22.0 and shouldn't be used in new projects
|
|
1480
1475
|
|
|
1481
|
-
|
|
1476
|
+
You can create a cancel token using the `CancelToken.source` factory as shown below:
|
|
1482
1477
|
|
|
1483
1478
|
```js
|
|
1484
1479
|
const CancelToken = axios.CancelToken;
|
|
@@ -1510,7 +1505,7 @@ axios.post(
|
|
|
1510
1505
|
source.cancel('Operation canceled by the user.');
|
|
1511
1506
|
```
|
|
1512
1507
|
|
|
1513
|
-
You can also
|
|
1508
|
+
You can also create a cancel token by passing an executor function to the `CancelToken` constructor:
|
|
1514
1509
|
|
|
1515
1510
|
```js
|
|
1516
1511
|
const CancelToken = axios.CancelToken;
|
|
@@ -1527,8 +1522,8 @@ axios.get('/user/12345', {
|
|
|
1527
1522
|
cancel();
|
|
1528
1523
|
```
|
|
1529
1524
|
|
|
1530
|
-
> Note
|
|
1531
|
-
> If a cancellation token is already cancelled
|
|
1525
|
+
> **Note:** you can cancel several requests with the same cancel token/abort controller.
|
|
1526
|
+
> 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.
|
|
1532
1527
|
|
|
1533
1528
|
> During the transition period, you can use both cancellation APIs, even for the same request:
|
|
1534
1529
|
|
|
@@ -1536,7 +1531,7 @@ cancel();
|
|
|
1536
1531
|
|
|
1537
1532
|
### URLSearchParams
|
|
1538
1533
|
|
|
1539
|
-
By default, axios serializes JavaScript objects to `JSON`. To send data
|
|
1534
|
+
By default, axios serializes JavaScript objects to `JSON`. To send data in the [`application/x-www-form-urlencoded`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) format 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).
|
|
1540
1535
|
|
|
1541
1536
|
```js
|
|
1542
1537
|
const params = new URLSearchParams({ foo: 'bar' });
|
|
@@ -1544,9 +1539,9 @@ params.append('extraparam', 'value');
|
|
|
1544
1539
|
axios.post('/foo', params);
|
|
1545
1540
|
```
|
|
1546
1541
|
|
|
1547
|
-
### Query string (
|
|
1542
|
+
### Query string (Older browsers)
|
|
1548
1543
|
|
|
1549
|
-
For very old browsers,
|
|
1544
|
+
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).
|
|
1550
1545
|
|
|
1551
1546
|
Alternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library:
|
|
1552
1547
|
|
|
@@ -1555,7 +1550,7 @@ const qs = require('qs');
|
|
|
1555
1550
|
axios.post('/foo', qs.stringify({ bar: 123 }));
|
|
1556
1551
|
```
|
|
1557
1552
|
|
|
1558
|
-
|
|
1553
|
+
Or in another way (ES6),
|
|
1559
1554
|
|
|
1560
1555
|
```js
|
|
1561
1556
|
import qs from 'qs';
|
|
@@ -1571,7 +1566,7 @@ axios(options);
|
|
|
1571
1566
|
|
|
1572
1567
|
### Older Node.js versions
|
|
1573
1568
|
|
|
1574
|
-
For older Node.js engines, use the [`querystring`](https://nodejs.org/api/querystring.html) module:
|
|
1569
|
+
For older Node.js engines, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
|
|
1575
1570
|
|
|
1576
1571
|
```js
|
|
1577
1572
|
const querystring = require('querystring');
|
|
@@ -1580,11 +1575,11 @@ axios.post('https://something.com/', querystring.stringify({ foo: 'bar' }));
|
|
|
1580
1575
|
|
|
1581
1576
|
You can also use the [`qs`](https://github.com/ljharb/qs) library.
|
|
1582
1577
|
|
|
1583
|
-
> Note
|
|
1578
|
+
> **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.
|
|
1584
1579
|
|
|
1585
|
-
### Automatic serialization to URLSearchParams
|
|
1580
|
+
### 🆕 Automatic serialization to URLSearchParams
|
|
1586
1581
|
|
|
1587
|
-
Axios automatically
|
|
1582
|
+
Axios will automatically serialize the data object to urlencoded format if the content-type header is set to "application/x-www-form-urlencoded".
|
|
1588
1583
|
|
|
1589
1584
|
```js
|
|
1590
1585
|
const data = {
|
|
@@ -1602,7 +1597,7 @@ await axios.postForm('https://postman-echo.com/post', data, {
|
|
|
1602
1597
|
});
|
|
1603
1598
|
```
|
|
1604
1599
|
|
|
1605
|
-
The server
|
|
1600
|
+
The server will handle it as:
|
|
1606
1601
|
|
|
1607
1602
|
```js
|
|
1608
1603
|
{
|
|
@@ -1619,7 +1614,7 @@ The server receives these fields:
|
|
|
1619
1614
|
}
|
|
1620
1615
|
```
|
|
1621
1616
|
|
|
1622
|
-
If your backend body
|
|
1617
|
+
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
|
|
1623
1618
|
|
|
1624
1619
|
```js
|
|
1625
1620
|
const app = express();
|
|
@@ -1638,8 +1633,8 @@ server = app.listen(3000);
|
|
|
1638
1633
|
|
|
1639
1634
|
### FormData
|
|
1640
1635
|
|
|
1641
|
-
To send data as `multipart/form-data
|
|
1642
|
-
|
|
1636
|
+
To send the data as a `multipart/form-data` you need to pass a formData instance as a payload.
|
|
1637
|
+
Setting the `Content-Type` header is not required as Axios guesses it based on the payload type.
|
|
1643
1638
|
|
|
1644
1639
|
```js
|
|
1645
1640
|
const formData = new FormData();
|
|
@@ -1648,7 +1643,7 @@ formData.append('foo', 'bar');
|
|
|
1648
1643
|
axios.post('https://httpbin.org/post', formData);
|
|
1649
1644
|
```
|
|
1650
1645
|
|
|
1651
|
-
In node.js, use the [`form-data`](https://github.com/form-data/form-data) library:
|
|
1646
|
+
In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
|
|
1652
1647
|
|
|
1653
1648
|
```js
|
|
1654
1649
|
const FormData = require('form-data');
|
|
@@ -1663,12 +1658,12 @@ axios.post('https://example.com', form);
|
|
|
1663
1658
|
|
|
1664
1659
|
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.
|
|
1665
1660
|
|
|
1666
|
-
### Automatic serialization to FormData
|
|
1661
|
+
### 🆕 Automatic serialization to FormData
|
|
1667
1662
|
|
|
1668
|
-
|
|
1663
|
+
Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
|
|
1669
1664
|
header is set to `multipart/form-data`.
|
|
1670
1665
|
|
|
1671
|
-
|
|
1666
|
+
The following request will submit the data in a FormData format (Browser & Node.js):
|
|
1672
1667
|
|
|
1673
1668
|
```js
|
|
1674
1669
|
import axios from 'axios';
|
|
@@ -1686,9 +1681,10 @@ axios
|
|
|
1686
1681
|
.then(({ data }) => console.log(data));
|
|
1687
1682
|
```
|
|
1688
1683
|
|
|
1689
|
-
|
|
1684
|
+
In the `node.js` build, the ([`form-data`](https://github.com/form-data/form-data)) polyfill is used by default.
|
|
1690
1685
|
|
|
1691
|
-
You can
|
|
1686
|
+
You can overload the FormData class by setting the `env.FormData` config variable,
|
|
1687
|
+
but you probably won't need it in most cases:
|
|
1692
1688
|
|
|
1693
1689
|
```js
|
|
1694
1690
|
const axios = require('axios');
|
|
@@ -1707,30 +1703,30 @@ axios
|
|
|
1707
1703
|
.then(({ data }) => console.log(data));
|
|
1708
1704
|
```
|
|
1709
1705
|
|
|
1710
|
-
|
|
1706
|
+
Axios FormData serializer supports some special endings to perform the following operations:
|
|
1711
1707
|
|
|
1712
1708
|
- `{}` - serialize the value with JSON.stringify
|
|
1713
1709
|
- `[]` - unwrap the array-like object as separate fields with the same key
|
|
1714
1710
|
|
|
1715
|
-
> Note
|
|
1711
|
+
> **Note**: unwrap/expand operation will be used by default on arrays and FileList objects
|
|
1716
1712
|
|
|
1717
1713
|
FormData serializer supports additional options via `config.formSerializer: object` property to handle rare cases:
|
|
1718
1714
|
|
|
1719
|
-
- `visitor: Function` - user-defined visitor function that
|
|
1715
|
+
- `visitor: Function` - user-defined visitor function that will be called recursively to serialize the data object
|
|
1720
1716
|
to a `FormData` object by following custom rules.
|
|
1721
1717
|
|
|
1722
1718
|
- `dots: boolean = false` - use dot notation instead of brackets to serialize arrays and objects;
|
|
1723
1719
|
|
|
1724
1720
|
- `metaTokens: boolean = true` - add the special ending (e.g `user{}: '{"name": "John"}'`) in the FormData key.
|
|
1725
|
-
|
|
1721
|
+
The back-end body-parser could potentially use this meta-information to automatically parse the value as JSON.
|
|
1726
1722
|
|
|
1727
|
-
- `indexes: null|false|true = false` - controls how
|
|
1723
|
+
- `indexes: null|false|true = false` - controls how indexes will be added to unwrapped keys of `flat` array-like objects.
|
|
1728
1724
|
- `null` - don't add brackets (`arr: 1`, `arr: 2`, `arr: 3`)
|
|
1729
1725
|
- `false`(default) - add empty brackets (`arr[]: 1`, `arr[]: 2`, `arr[]: 3`)
|
|
1730
1726
|
- `true` - add brackets with indexes (`arr[0]: 1`, `arr[1]: 2`, `arr[2]: 3`)
|
|
1731
1727
|
- `maxDepth: number = 100` - maximum object nesting depth the serializer will recurse into. If the
|
|
1732
1728
|
input object exceeds this depth, an `AxiosError` with `code: 'ERR_FORM_DATA_DEPTH_EXCEEDED'` is
|
|
1733
|
-
thrown instead of overflowing the call stack. This protects server applications from DoS
|
|
1729
|
+
thrown instead of overflowing the call stack. This protects server-side applications from DoS
|
|
1734
1730
|
attacks via deeply nested payloads. Set to `Infinity` to disable the limit and restore pre-fix behaviour.
|
|
1735
1731
|
|
|
1736
1732
|
```js
|
|
@@ -1741,7 +1737,7 @@ axios.postForm('/api', data, { formSerializer: { maxDepth: 200 } });
|
|
|
1741
1737
|
axios.get('/api', { params: data, paramsSerializer: { maxDepth: 200 } });
|
|
1742
1738
|
```
|
|
1743
1739
|
|
|
1744
|
-
|
|
1740
|
+
Let's say we have an object like this one:
|
|
1745
1741
|
|
|
1746
1742
|
```js
|
|
1747
1743
|
const obj = {
|
|
@@ -1756,7 +1752,7 @@ const obj = {
|
|
|
1756
1752
|
};
|
|
1757
1753
|
```
|
|
1758
1754
|
|
|
1759
|
-
The Axios serializer
|
|
1755
|
+
The following steps will be executed by the Axios serializer internally:
|
|
1760
1756
|
|
|
1761
1757
|
```js
|
|
1762
1758
|
const formData = new FormData();
|
|
@@ -1774,11 +1770,12 @@ formData.append('users[1][surname]', 'Anderson');
|
|
|
1774
1770
|
formData.append('obj2{}', '[{"x":1}]');
|
|
1775
1771
|
```
|
|
1776
1772
|
|
|
1777
|
-
Axios supports `postForm`, `putForm`,
|
|
1773
|
+
Axios supports the following shortcut methods: `postForm`, `putForm`, `patchForm`
|
|
1774
|
+
which are just the corresponding http methods with the `Content-Type` header preset to `multipart/form-data`.
|
|
1778
1775
|
|
|
1779
|
-
## Posting
|
|
1776
|
+
## Files Posting
|
|
1780
1777
|
|
|
1781
|
-
|
|
1778
|
+
You can easily submit a single file:
|
|
1782
1779
|
|
|
1783
1780
|
```js
|
|
1784
1781
|
await axios.postForm('https://httpbin.org/post', {
|
|
@@ -1801,9 +1798,9 @@ await axios.postForm('https://httpbin.org/post', {
|
|
|
1801
1798
|
await axios.postForm('https://httpbin.org/post', document.querySelector('#fileInput').files);
|
|
1802
1799
|
```
|
|
1803
1800
|
|
|
1804
|
-
|
|
1801
|
+
All files will be sent with the same field names: `files[]`.
|
|
1805
1802
|
|
|
1806
|
-
## HTML
|
|
1803
|
+
## 🆕 HTML Form Posting (browser)
|
|
1807
1804
|
|
|
1808
1805
|
Pass an HTML Form element as a payload to submit it as `multipart/form-data` content.
|
|
1809
1806
|
|
|
@@ -1841,7 +1838,7 @@ For example, the Form
|
|
|
1841
1838
|
</form>
|
|
1842
1839
|
```
|
|
1843
1840
|
|
|
1844
|
-
|
|
1841
|
+
will be submitted as the following JSON object:
|
|
1845
1842
|
|
|
1846
1843
|
```js
|
|
1847
1844
|
{
|
|
@@ -1863,10 +1860,10 @@ submits this JSON object:
|
|
|
1863
1860
|
|
|
1864
1861
|
Sending `Blobs`/`Files` as JSON (`base64`) is not currently supported.
|
|
1865
1862
|
|
|
1866
|
-
## Progress capturing
|
|
1863
|
+
## 🆕 Progress capturing
|
|
1867
1864
|
|
|
1868
|
-
Axios
|
|
1869
|
-
|
|
1865
|
+
Axios supports both browser and node environments to capture request upload/download progress.
|
|
1866
|
+
The frequency of progress events is forced to be limited to `3` times per second.
|
|
1870
1867
|
|
|
1871
1868
|
```js
|
|
1872
1869
|
await axios.post(url, data, {
|
|
@@ -1912,14 +1909,14 @@ const { data } = await axios.post(SERVER_URL, readableStream, {
|
|
|
1912
1909
|
});
|
|
1913
1910
|
```
|
|
1914
1911
|
|
|
1915
|
-
> Note
|
|
1912
|
+
> **Note:**
|
|
1916
1913
|
> Capturing FormData upload progress is not currently supported in node.js environments.
|
|
1917
1914
|
|
|
1918
|
-
> Warning
|
|
1919
|
-
>
|
|
1920
|
-
>
|
|
1915
|
+
> **⚠️ Warning**
|
|
1916
|
+
> It is recommended to disable redirects by setting maxRedirects: 0 to upload the stream in the **node.js** environment,
|
|
1917
|
+
> as the follow-redirects package will buffer the entire stream in RAM without following the "backpressure" algorithm.
|
|
1921
1918
|
|
|
1922
|
-
## Rate limiting
|
|
1919
|
+
## 🆕 Rate limiting
|
|
1923
1920
|
|
|
1924
1921
|
Download and upload rate limits can only be set for the http adapter (node.js):
|
|
1925
1922
|
|
|
@@ -1933,24 +1930,25 @@ const { data } = await axios.post(LOCAL_SERVER_URL, myBuffer, {
|
|
|
1933
1930
|
});
|
|
1934
1931
|
```
|
|
1935
1932
|
|
|
1936
|
-
## AxiosHeaders
|
|
1933
|
+
## 🆕 AxiosHeaders
|
|
1937
1934
|
|
|
1938
|
-
Axios
|
|
1939
|
-
HTTP
|
|
1940
|
-
|
|
1935
|
+
Axios has its own `AxiosHeaders` class to manipulate headers using a Map-like API that guarantees caseless work.
|
|
1936
|
+
Although HTTP is case-insensitive in headers, Axios will retain the case of the original header for stylistic reasons
|
|
1937
|
+
and as a workaround when servers mistakenly consider the header's case.
|
|
1938
|
+
The old approach of directly manipulating the headers object is still available, but deprecated and not recommended for future usage.
|
|
1941
1939
|
|
|
1942
1940
|
### Working with headers
|
|
1943
1941
|
|
|
1944
|
-
An
|
|
1945
|
-
|
|
1942
|
+
An AxiosHeaders object instance can contain different types of internal values. that control setting and merging logic.
|
|
1943
|
+
The final headers object with string values is obtained by Axios by calling the `toJSON` method.
|
|
1946
1944
|
|
|
1947
1945
|
> Note: By JSON here we mean an object consisting only of string values intended to be sent over the network.
|
|
1948
1946
|
|
|
1949
1947
|
The header value can be one of the following types:
|
|
1950
1948
|
|
|
1951
|
-
- `string` - normal string value sent to the server
|
|
1949
|
+
- `string` - normal string value that will be sent to the server
|
|
1952
1950
|
- `null` - skip header when rendering to JSON
|
|
1953
|
-
- `false` - skip header when rendering to JSON
|
|
1951
|
+
- `false` - skip header when rendering to JSON, additionally indicates that `set` method must be called with `rewrite` option set to `true`
|
|
1954
1952
|
to overwrite this value (Axios uses this internally to allow users to opt out of installing certain headers like `User-Agent` or `Content-Type`)
|
|
1955
1953
|
- `undefined` - value is not set
|
|
1956
1954
|
|
|
@@ -1967,7 +1965,7 @@ axios.interceptors.request.use((request: InternalAxiosRequestConfig) => {
|
|
|
1967
1965
|
'My-set-header2': 'my-set-value2',
|
|
1968
1966
|
});
|
|
1969
1967
|
|
|
1970
|
-
request.headers.set('User-Agent', false); //
|
|
1968
|
+
request.headers.set('User-Agent', false); // disable subsequent setting the header by Axios
|
|
1971
1969
|
|
|
1972
1970
|
request.headers.setContentType('text/plain');
|
|
1973
1971
|
|
|
@@ -2035,7 +2033,7 @@ Constructs a new `AxiosHeaders` instance.
|
|
|
2035
2033
|
constructor(headers?: RawAxiosHeaders | AxiosHeaders | string);
|
|
2036
2034
|
```
|
|
2037
2035
|
|
|
2038
|
-
If the headers object is a string,
|
|
2036
|
+
If the headers object is a string, it will be parsed as RAW HTTP headers.
|
|
2039
2037
|
|
|
2040
2038
|
```js
|
|
2041
2039
|
const headers = new AxiosHeaders(`
|
|
@@ -2066,7 +2064,7 @@ The `rewrite` argument controls the overwriting behavior:
|
|
|
2066
2064
|
- `undefined` (default) - overwrite the header unless its value is set to `false`
|
|
2067
2065
|
- `true` - rewrite anyway
|
|
2068
2066
|
|
|
2069
|
-
The option can also accept a user-defined function that determines whether
|
|
2067
|
+
The option can also accept a user-defined function that determines whether the value should be overwritten or not.
|
|
2070
2068
|
|
|
2071
2069
|
Returns `this`.
|
|
2072
2070
|
|
|
@@ -2130,7 +2128,7 @@ clear(matcher?: AxiosHeaderMatcher): boolean;
|
|
|
2130
2128
|
```
|
|
2131
2129
|
|
|
2132
2130
|
Removes all headers.
|
|
2133
|
-
Unlike the `delete` method matcher, this optional matcher
|
|
2131
|
+
Unlike the `delete` method matcher, this optional matcher will be used to match against the header name rather than the value.
|
|
2134
2132
|
|
|
2135
2133
|
```ts
|
|
2136
2134
|
const headers = new AxiosHeaders({
|
|
@@ -2174,18 +2172,17 @@ Returns `this`.
|
|
|
2174
2172
|
concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>): AxiosHeaders;
|
|
2175
2173
|
```
|
|
2176
2174
|
|
|
2177
|
-
Merges the instance with targets into a new `AxiosHeaders` instance. If the target is a string,
|
|
2175
|
+
Merges the instance with targets into a new `AxiosHeaders` instance. If the target is a string, it will be parsed as RAW HTTP headers.
|
|
2178
2176
|
|
|
2179
2177
|
Returns a new `AxiosHeaders` instance.
|
|
2180
2178
|
|
|
2181
2179
|
### AxiosHeaders#toJSON(asStrings?)
|
|
2182
2180
|
|
|
2183
2181
|
```
|
|
2184
|
-
toJSON(asStrings
|
|
2185
|
-
toJSON(asStrings?: false): Record<string, string | string[]>;
|
|
2182
|
+
toJSON(asStrings?: boolean): RawAxiosHeaders;
|
|
2186
2183
|
```
|
|
2187
2184
|
|
|
2188
|
-
|
|
2185
|
+
Resolve all internal header values into a new null prototype object.
|
|
2189
2186
|
Set `asStrings` to true to resolve arrays as a string containing all elements, separated by commas.
|
|
2190
2187
|
|
|
2191
2188
|
### AxiosHeaders.from(thing?)
|
|
@@ -2195,7 +2192,7 @@ from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
|
|
2195
2192
|
```
|
|
2196
2193
|
|
|
2197
2194
|
Returns a new `AxiosHeaders` instance created from the raw headers passed in,
|
|
2198
|
-
or returns the given headers object if it's
|
|
2195
|
+
or simply returns the given headers object if it's an `AxiosHeaders` instance.
|
|
2199
2196
|
|
|
2200
2197
|
### AxiosHeaders.concat(...targets)
|
|
2201
2198
|
|
|
@@ -2219,10 +2216,11 @@ The following shortcuts are available:
|
|
|
2219
2216
|
|
|
2220
2217
|
- `setContentEncoding`, `getContentEncoding`, `hasContentEncoding`
|
|
2221
2218
|
|
|
2222
|
-
## Fetch adapter
|
|
2219
|
+
## 🔥 Fetch adapter
|
|
2223
2220
|
|
|
2224
|
-
|
|
2225
|
-
|
|
2221
|
+
Fetch adapter was introduced in `v1.7.0`. By default, it will be used if `xhr` and `http` adapters are not available in the build,
|
|
2222
|
+
or not supported by the environment.
|
|
2223
|
+
To use it by default, it must be selected explicitly:
|
|
2226
2224
|
|
|
2227
2225
|
```js
|
|
2228
2226
|
const { data } = axios.get(url, {
|
|
@@ -2240,19 +2238,20 @@ const fetchAxios = axios.create({
|
|
|
2240
2238
|
const { data } = fetchAxios.get(url);
|
|
2241
2239
|
```
|
|
2242
2240
|
|
|
2243
|
-
The adapter supports the same
|
|
2244
|
-
|
|
2241
|
+
The adapter supports the same functionality as the `xhr` adapter, **including upload and download progress capturing**.
|
|
2242
|
+
Also, it supports additional response types such as `stream` and `formdata` (if supported by the environment).
|
|
2245
2243
|
|
|
2246
|
-
### Custom fetch
|
|
2244
|
+
### 🔥 Custom fetch
|
|
2247
2245
|
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
This
|
|
2246
|
+
Starting from `v1.12.0`, you can customize the fetch adapter to use a custom fetch API instead of environment globals.
|
|
2247
|
+
You can pass a custom `fetch` function, `Request`, and `Response` constructors via env config.
|
|
2248
|
+
This can be helpful in case of custom environments & app frameworks.
|
|
2251
2249
|
|
|
2252
|
-
|
|
2253
|
-
If your custom fetch
|
|
2250
|
+
Also, when using a custom fetch, you may need to set custom Request and Response too. If you don't set them, global objects will be used.
|
|
2251
|
+
If your custom fetch api does not have these objects, and the globals are incompatible with a custom fetch,
|
|
2252
|
+
you must disable their use inside the fetch adapter by passing null.
|
|
2254
2253
|
|
|
2255
|
-
> Note: Setting `Request`
|
|
2254
|
+
> Note: Setting `Request` & `Response` to `null` will make it impossible for the fetch adapter to capture the upload & download progress.
|
|
2256
2255
|
|
|
2257
2256
|
Basic example:
|
|
2258
2257
|
|
|
@@ -2272,7 +2271,7 @@ const instance = axios.create({
|
|
|
2272
2271
|
});
|
|
2273
2272
|
```
|
|
2274
2273
|
|
|
2275
|
-
#### Using with Tauri
|
|
2274
|
+
#### 🔥 Using with Tauri
|
|
2276
2275
|
|
|
2277
2276
|
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.
|
|
2278
2277
|
|
|
@@ -2293,9 +2292,10 @@ const instance = axios.create({
|
|
|
2293
2292
|
const { data } = await instance.get('https://google.com');
|
|
2294
2293
|
```
|
|
2295
2294
|
|
|
2296
|
-
#### Using with SvelteKit
|
|
2295
|
+
#### 🔥 Using with SvelteKit
|
|
2297
2296
|
|
|
2298
|
-
[SvelteKit](https://svelte.dev/docs/kit/web-standards#Fetch-APIs)
|
|
2297
|
+
[SvelteKit](https://svelte.dev/docs/kit/web-standards#Fetch-APIs) framework has a custom implementation of the fetch function for server rendering (so called `load` functions), and also uses relative paths,
|
|
2298
|
+
which makes it incompatible with the standard URL API. So, Axios must be configured to use the custom fetch API:
|
|
2299
2299
|
|
|
2300
2300
|
```js
|
|
2301
2301
|
export async function load({ fetch }) {
|
|
@@ -2312,13 +2312,13 @@ export async function load({ fetch }) {
|
|
|
2312
2312
|
}
|
|
2313
2313
|
```
|
|
2314
2314
|
|
|
2315
|
-
#### HTTP/2
|
|
2315
|
+
#### HTTP/2 Support
|
|
2316
2316
|
|
|
2317
|
-
Axios supports HTTP/2
|
|
2317
|
+
Axios supports HTTP/2 via the Node.js `http` adapter (introduced in v1.13.0).
|
|
2318
2318
|
|
|
2319
|
-
|
|
2319
|
+
This support depends on the runtime environment. Since Axios relies on Node.js APIs, HTTP/2 functionality is available in supported Node.js versions, but may not work in other environments (such as Bun or Deno).
|
|
2320
2320
|
|
|
2321
|
-
Options like `httpVersion` and `http2Options` are adapter-specific and may not behave
|
|
2321
|
+
Options like `httpVersion` and `http2Options` are adapter-specific and may not behave consistently across all environments.
|
|
2322
2322
|
|
|
2323
2323
|
Note: HTTP/2 redirects are currently not supported by the HTTP/2 adapter.
|
|
2324
2324
|
|
|
@@ -2340,7 +2340,7 @@ const { data, headers, status } = await axios.post('https://httpbin.org/post', f
|
|
|
2340
2340
|
|
|
2341
2341
|
## Semver
|
|
2342
2342
|
|
|
2343
|
-
Axios
|
|
2343
|
+
Since Axios has reached a `v.1.0.0` we will fully embrace semver as per the spec [here](https://semver.org/)
|
|
2344
2344
|
|
|
2345
2345
|
## Promises
|
|
2346
2346
|
|
|
@@ -2365,10 +2365,10 @@ try {
|
|
|
2365
2365
|
}
|
|
2366
2366
|
```
|
|
2367
2367
|
|
|
2368
|
-
Because axios publishes an ESM default export and a CJS `module.exports`,
|
|
2369
|
-
The recommended setting is `"moduleResolution": "node16"
|
|
2370
|
-
If
|
|
2371
|
-
If you compile TypeScript to CJS and can
|
|
2368
|
+
Because axios dual publishes with an ESM default export and a CJS `module.exports`, there are some caveats.
|
|
2369
|
+
The recommended setting is to use `"moduleResolution": "node16"` (this is implied by `"module": "node16"`). Note that this requires TypeScript 4.7 or greater.
|
|
2370
|
+
If use ESM, your settings should be fine.
|
|
2371
|
+
If you compile TypeScript to CJS and you can’t use `"moduleResolution": "node 16"`, you have to enable `esModuleInterop`.
|
|
2372
2372
|
If you use TypeScript to type check CJS JavaScript code, your only option is to use `"moduleResolution": "node16"`.
|
|
2373
2373
|
|
|
2374
2374
|
You can also create a custom instance with typed interceptors:
|
|
@@ -2389,7 +2389,7 @@ apiClient.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
|
|
2389
2389
|
|
|
2390
2390
|
## Online one-click setup
|
|
2391
2391
|
|
|
2392
|
-
You can use Gitpod,
|
|
2392
|
+
You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online.
|
|
2393
2393
|
|
|
2394
2394
|
[](https://gitpod.io/#https://github.com/axios/axios/blob/main/examples/server.js)
|
|
2395
2395
|
|
|
@@ -2408,7 +2408,7 @@ npm rebuild husky && npx husky
|
|
|
2408
2408
|
|
|
2409
2409
|
Run those two commands once per fresh checkout. You do **not** need to re-run them after every subsequent `npm install`.
|
|
2410
2410
|
|
|
2411
|
-
Do not remove `ignore-scripts=true` from `.npmrc` to "fix" this
|
|
2411
|
+
Do not remove `ignore-scripts=true` from `.npmrc` to "fix" this — that re-opens 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.
|
|
2412
2412
|
|
|
2413
2413
|
## Resources
|
|
2414
2414
|
|
|
@@ -2419,7 +2419,7 @@ Do not remove `ignore-scripts=true` from `.npmrc` to "fix" this. That reopens th
|
|
|
2419
2419
|
|
|
2420
2420
|
## Credits
|
|
2421
2421
|
|
|
2422
|
-
axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) in [AngularJS](https://angularjs.org/).
|
|
2422
|
+
axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) provided in [AngularJS](https://angularjs.org/). Ultimately axios is an effort to provide a standalone `$http`-like service for use outside of AngularJS.
|
|
2423
2423
|
|
|
2424
2424
|
## License
|
|
2425
2425
|
|