groove-dev 0.27.144 → 0.27.145
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/node_modules/@groove-dev/cli/package.json +1 -1
- package/node_modules/@groove-dev/daemon/package.json +1 -1
- package/node_modules/@groove-dev/daemon/src/conversations.js +18 -48
- package/node_modules/@groove-dev/daemon/src/routes/agents.js +6 -83
- package/node_modules/@groove-dev/gui/dist/assets/{index-BcoF6_eF.js → index-Bxc0gU06.js} +232 -238
- package/node_modules/@groove-dev/gui/dist/assets/index-C0pztKBn.css +1 -0
- package/node_modules/@groove-dev/gui/dist/index.html +2 -2
- package/node_modules/@groove-dev/gui/package.json +1 -1
- package/node_modules/@groove-dev/gui/src/components/agents/agent-feed.jsx +80 -95
- package/node_modules/@groove-dev/gui/src/components/agents/agent-panel.jsx +2 -70
- package/node_modules/@groove-dev/gui/src/components/chat/chat-header.jsx +2 -0
- package/node_modules/@groove-dev/gui/src/components/chat/chat-input.jsx +68 -66
- package/node_modules/@groove-dev/gui/src/components/chat/chat-view.jsx +4 -8
- package/node_modules/@groove-dev/gui/src/components/lab/chat-playground.jsx +39 -31
- package/node_modules/@groove-dev/gui/src/components/lab/parameter-panel.jsx +66 -65
- package/node_modules/@groove-dev/gui/src/components/lab/preset-manager.jsx +17 -14
- package/node_modules/@groove-dev/gui/src/components/lab/runtime-config.jsx +126 -127
- package/node_modules/@groove-dev/gui/src/components/lab/system-prompt-editor.jsx +10 -8
- package/node_modules/@groove-dev/gui/src/components/ui/slider.jsx +8 -8
- package/node_modules/@groove-dev/gui/src/lib/status.js +1 -0
- package/node_modules/@groove-dev/gui/src/stores/groove.js +17 -0
- package/node_modules/@groove-dev/gui/src/stores/slices/agents-slice.js +8 -1
- package/node_modules/@groove-dev/gui/src/stores/slices/chat-slice.js +13 -14
- package/node_modules/@groove-dev/gui/src/views/model-lab.jsx +41 -10
- package/node_modules/@groove-dev/gui/src/views/models.jsx +57 -36
- package/node_modules/axios/CHANGELOG.md +260 -0
- package/node_modules/axios/README.md +595 -223
- package/node_modules/axios/dist/axios.js +1460 -1090
- package/node_modules/axios/dist/axios.js.map +1 -1
- 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 +1560 -1132
- package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
- package/node_modules/axios/dist/esm/axios.js +1557 -1128
- package/node_modules/axios/dist/esm/axios.js.map +1 -1
- 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 +1594 -1057
- package/node_modules/axios/dist/node/axios.cjs.map +1 -1
- package/node_modules/axios/index.d.cts +40 -41
- package/node_modules/axios/index.d.ts +151 -227
- package/node_modules/axios/index.js +2 -0
- package/node_modules/axios/lib/adapters/adapters.js +4 -2
- package/node_modules/axios/lib/adapters/fetch.js +147 -16
- package/node_modules/axios/lib/adapters/http.js +306 -58
- package/node_modules/axios/lib/adapters/xhr.js +6 -2
- package/node_modules/axios/lib/core/Axios.js +7 -3
- package/node_modules/axios/lib/core/AxiosError.js +120 -34
- package/node_modules/axios/lib/core/AxiosHeaders.js +27 -25
- package/node_modules/axios/lib/core/buildFullPath.js +1 -1
- package/node_modules/axios/lib/core/dispatchRequest.js +19 -7
- package/node_modules/axios/lib/core/mergeConfig.js +21 -4
- package/node_modules/axios/lib/core/settle.js +7 -11
- package/node_modules/axios/lib/defaults/index.js +14 -9
- package/node_modules/axios/lib/env/data.js +1 -1
- package/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +1 -2
- package/node_modules/axios/lib/helpers/buildURL.js +1 -1
- package/node_modules/axios/lib/helpers/cookies.js +14 -2
- package/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +28 -1
- package/node_modules/axios/lib/helpers/formDataToJSON.js +3 -1
- package/node_modules/axios/lib/helpers/formDataToStream.js +3 -2
- package/node_modules/axios/lib/helpers/parseProtocol.js +1 -1
- package/node_modules/axios/lib/helpers/progressEventReducer.js +5 -5
- package/node_modules/axios/lib/helpers/resolveConfig.js +54 -18
- package/node_modules/axios/lib/helpers/shouldBypassProxy.js +74 -2
- package/node_modules/axios/lib/helpers/toFormData.js +10 -2
- package/node_modules/axios/lib/helpers/validator.js +3 -1
- package/node_modules/axios/lib/utils.js +33 -21
- package/node_modules/axios/package.json +17 -24
- package/node_modules/follow-redirects/README.md +7 -5
- package/node_modules/follow-redirects/index.js +24 -1
- package/node_modules/follow-redirects/package.json +1 -1
- package/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/daemon/package.json +1 -1
- package/packages/daemon/src/conversations.js +18 -48
- package/packages/daemon/src/routes/agents.js +6 -83
- package/packages/gui/dist/assets/{index-BcoF6_eF.js → index-Bxc0gU06.js} +232 -238
- package/packages/gui/dist/assets/index-C0pztKBn.css +1 -0
- package/packages/gui/dist/index.html +2 -2
- package/packages/gui/package.json +1 -1
- package/packages/gui/src/components/agents/agent-feed.jsx +80 -95
- package/packages/gui/src/components/agents/agent-panel.jsx +2 -70
- package/packages/gui/src/components/chat/chat-header.jsx +2 -0
- package/packages/gui/src/components/chat/chat-input.jsx +68 -66
- package/packages/gui/src/components/chat/chat-view.jsx +4 -8
- package/packages/gui/src/components/lab/chat-playground.jsx +39 -31
- package/packages/gui/src/components/lab/parameter-panel.jsx +66 -65
- package/packages/gui/src/components/lab/preset-manager.jsx +17 -14
- package/packages/gui/src/components/lab/runtime-config.jsx +126 -127
- package/packages/gui/src/components/lab/system-prompt-editor.jsx +10 -8
- package/packages/gui/src/components/ui/slider.jsx +8 -8
- package/packages/gui/src/lib/status.js +1 -0
- package/packages/gui/src/stores/groove.js +17 -0
- package/packages/gui/src/stores/slices/agents-slice.js +8 -1
- package/packages/gui/src/stores/slices/chat-slice.js +13 -14
- package/packages/gui/src/views/model-lab.jsx +41 -10
- package/packages/gui/src/views/models.jsx +57 -36
- package/node_modules/@groove-dev/gui/dist/assets/index-Dd7qhiEd.css +0 -1
- package/packages/gui/dist/assets/index-Dd7qhiEd.css +0 -1
|
@@ -1,32 +1,297 @@
|
|
|
1
|
-
<h3 align="center"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
<h3 align="center">💎 Platinum sponsors <br /></h3>
|
|
2
|
+
<table align="center">
|
|
3
|
+
<tr>
|
|
4
|
+
<td align="center" width="50%">
|
|
5
|
+
<a
|
|
6
|
+
href="https://thanks.dev/?utm_source=axios&utm_medium=sponsorlist&utm_campaign=sponsorship"
|
|
7
|
+
style="padding: 10px; display: inline-block"
|
|
8
|
+
target="_blank"
|
|
9
|
+
>
|
|
10
|
+
<img
|
|
11
|
+
width="90px"
|
|
12
|
+
height="90px"
|
|
13
|
+
src="https://images.opencollective.com/thanks-dev/360b917/logo/256.png?height=256"
|
|
14
|
+
alt="Thanks.dev"
|
|
15
|
+
/>
|
|
16
|
+
</a>
|
|
17
|
+
<p
|
|
18
|
+
align="center"
|
|
19
|
+
>
|
|
20
|
+
We're passionate about making open source sustainable. Scan your dependency tree to better understand which open source projects need funding.
|
|
21
|
+
</p>
|
|
22
|
+
<p align="center">
|
|
23
|
+
<a
|
|
24
|
+
href="https://thanks.dev/?utm_source=axios&utm_medium=readme_sponsorlist&utm_campaign=sponsorship"
|
|
25
|
+
target="_blank"
|
|
26
|
+
><b>thanks.dev</b></a
|
|
27
|
+
>
|
|
28
|
+
</p>
|
|
29
|
+
</td>
|
|
30
|
+
<td align="center" width="50%">
|
|
31
|
+
<a
|
|
32
|
+
href="https://hopper.security/?utm_source=axios&utm_medium=readme_sponsorlist&utm_campaign=sponsorship"
|
|
33
|
+
style="padding: 10px; display: inline-block"
|
|
34
|
+
target="_blank"
|
|
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
|
+
</td>
|
|
54
|
+
</tr>
|
|
55
|
+
</table>
|
|
56
|
+
<table align="center">
|
|
57
|
+
<tr>
|
|
58
|
+
<td align="center" width="50%">
|
|
59
|
+
<a
|
|
60
|
+
href="https://opencollective.com/axios/contribute"
|
|
61
|
+
target="_blank"
|
|
62
|
+
>💜 Become a sponsor</a
|
|
63
|
+
>
|
|
64
|
+
</td>
|
|
65
|
+
<td align="center" width="50%">
|
|
66
|
+
<a
|
|
67
|
+
href="https://opencollective.com/axios/contribute"
|
|
68
|
+
target="_blank"
|
|
69
|
+
>💜 Become a sponsor</a
|
|
70
|
+
>
|
|
71
|
+
</td>
|
|
72
|
+
</tr>
|
|
73
|
+
</table>
|
|
74
|
+
<h3 align="center">🥇 Gold sponsors <br /></h3>
|
|
75
|
+
<table align="center" width="100%">
|
|
76
|
+
<tr width="33.333333333333336%">
|
|
77
|
+
<td align="center" width="33.333333333333336%">
|
|
78
|
+
<a
|
|
79
|
+
href="https://www.principal.com/about-us?utm_source=axios&utm_medium=sponsorlist&utm_campaign=sponsorship"
|
|
80
|
+
style="padding: 10px; display: inline-block"
|
|
81
|
+
target="_blank"
|
|
82
|
+
>
|
|
83
|
+
<img
|
|
84
|
+
width="90px"
|
|
85
|
+
height="90px"
|
|
86
|
+
src="https://images.opencollective.com/principal/431e690/logo.png"
|
|
87
|
+
alt="Principal Financial Group"
|
|
88
|
+
/>
|
|
89
|
+
</a>
|
|
90
|
+
<p
|
|
91
|
+
align="center"
|
|
92
|
+
>
|
|
93
|
+
Free tools to help with your financial planning needs!
|
|
94
|
+
</p>
|
|
95
|
+
<p align="center">
|
|
96
|
+
<a
|
|
97
|
+
href="https://www.principal.com/about-us?utm_source=axios&utm_medium=readme_sponsorlist&utm_campaign=sponsorship"
|
|
98
|
+
target="_blank"
|
|
99
|
+
><b>principal.com</b></a
|
|
100
|
+
>
|
|
101
|
+
</p>
|
|
102
|
+
</td>
|
|
103
|
+
<td align="center" width="33.333333333333336%">
|
|
104
|
+
<a
|
|
105
|
+
href="https://opensource.sap.com?utm_source=axios&utm_medium=sponsorlist&utm_campaign=sponsorship"
|
|
106
|
+
style="padding: 10px; display: inline-block"
|
|
107
|
+
target="_blank"
|
|
108
|
+
>
|
|
109
|
+
<img
|
|
110
|
+
width="90px"
|
|
111
|
+
height="90px"
|
|
112
|
+
src="https://avatars.githubusercontent.com/u/2531208?s=200&v=4"
|
|
113
|
+
alt="SAP"
|
|
114
|
+
/>
|
|
115
|
+
</a>
|
|
116
|
+
<p
|
|
117
|
+
align="center"
|
|
118
|
+
title="SAP SE, a global software company, is one of the largest vendors of ERP and other enterprise applications."
|
|
119
|
+
>
|
|
120
|
+
BSAP SE, a global software company, is one of the largest vendors of ERP and other enterprise applications.
|
|
121
|
+
</p>
|
|
122
|
+
<p align="center">
|
|
123
|
+
<a
|
|
124
|
+
href="https://opensource.sap.com?utm_source=axios&utm_medium=readme_sponsorlist&utm_campaign=sponsorship"
|
|
125
|
+
target="_blank"
|
|
126
|
+
><b>opensource.sap.com</b></a
|
|
127
|
+
>
|
|
128
|
+
</p>
|
|
129
|
+
</td>
|
|
130
|
+
<td align="center" width="33.333333333333336%">
|
|
131
|
+
<a
|
|
132
|
+
href="https://www.descope.com/?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship"
|
|
133
|
+
style="padding: 10px; display: inline-block"
|
|
134
|
+
target="_blank"
|
|
135
|
+
>
|
|
136
|
+
<img
|
|
137
|
+
width="90px"
|
|
138
|
+
height="90px"
|
|
139
|
+
src="https://images.opencollective.com/descope/b53243e/logo.png"
|
|
140
|
+
alt="Descope"
|
|
141
|
+
/>
|
|
142
|
+
</a>
|
|
143
|
+
<p
|
|
144
|
+
align="center"
|
|
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."
|
|
146
|
+
>
|
|
147
|
+
Reduce user friction, prevent account takeover, and get a 360° view of your customer and agentic identities with the Descope External IAM platform.
|
|
148
|
+
</p>
|
|
149
|
+
<p align="center">
|
|
150
|
+
<a
|
|
151
|
+
href="https://www.descope.com/?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship"
|
|
152
|
+
target="_blank"
|
|
153
|
+
><b>descope.com</b></a
|
|
154
|
+
>
|
|
155
|
+
</p>
|
|
156
|
+
</td>
|
|
157
|
+
</tr>
|
|
158
|
+
<tr width="33.333333333333336%">
|
|
159
|
+
<td align="center" width="33.333333333333336%">
|
|
160
|
+
<a
|
|
161
|
+
href="https://stytch.com/"
|
|
162
|
+
style="padding: 10px; display: inline-block"
|
|
163
|
+
target="_blank"
|
|
164
|
+
>
|
|
165
|
+
<img
|
|
166
|
+
width="90px"
|
|
167
|
+
height="90px"
|
|
168
|
+
src="https://images.opencollective.com/stytch/f84ce43/logo/256.png?height=256"
|
|
169
|
+
alt="Stytch"
|
|
170
|
+
/>
|
|
171
|
+
</a>
|
|
172
|
+
<p
|
|
173
|
+
align="center"
|
|
174
|
+
>
|
|
175
|
+
The identity platform for humans & AI agents
|
|
176
|
+
</p>
|
|
177
|
+
<p align="center">
|
|
178
|
+
<a
|
|
179
|
+
href="https://stytch.com"
|
|
180
|
+
target="_blank"
|
|
181
|
+
><b>stytch.com</b></a
|
|
182
|
+
>
|
|
183
|
+
</p>
|
|
184
|
+
</td>
|
|
185
|
+
<td align="center" width="33.333333333333336%">
|
|
186
|
+
<a
|
|
187
|
+
href="https://rxdb.info/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship&utm_content=logo"
|
|
188
|
+
style="padding: 10px; display: inline-block"
|
|
189
|
+
target="_blank"
|
|
190
|
+
>
|
|
191
|
+
<img
|
|
192
|
+
width="90px"
|
|
193
|
+
height="90px"
|
|
194
|
+
src="https://rxdb.info/files/logo/logo_text_white.svg"
|
|
195
|
+
alt="RxDB"
|
|
196
|
+
/>
|
|
197
|
+
</a>
|
|
198
|
+
<p
|
|
199
|
+
align="center"
|
|
200
|
+
>
|
|
201
|
+
RxDB is a NoSQL database for JavaScript that runs directly in your app.
|
|
202
|
+
</p>
|
|
203
|
+
<p align="center">
|
|
204
|
+
<a
|
|
205
|
+
href="https://rxdb.info/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship&utm_content=logo"
|
|
206
|
+
target="_blank"
|
|
207
|
+
><b>rxdb.info</b></a
|
|
208
|
+
>
|
|
209
|
+
</p>
|
|
210
|
+
</td>
|
|
211
|
+
<td align="center" width="33.333333333333336%">
|
|
212
|
+
<a
|
|
213
|
+
href="https://poprey.com/?utm_source=axios&utm_medium=sponsorlist&utm_campaign=sponsorship"
|
|
214
|
+
style="padding: 10px; display: inline-block"
|
|
215
|
+
target="_blank"
|
|
216
|
+
>
|
|
217
|
+
<img
|
|
218
|
+
width="70px"
|
|
219
|
+
height="70px"
|
|
220
|
+
src="https://images.opencollective.com/instagram-likes/2a72a03/avatar.png"
|
|
221
|
+
alt="Poprey"
|
|
222
|
+
/>
|
|
223
|
+
</a>
|
|
224
|
+
<p align="center">
|
|
225
|
+
Buy Instagram Likes
|
|
226
|
+
</p>
|
|
227
|
+
<p align="center">
|
|
228
|
+
<a
|
|
229
|
+
href="https://poprey.com/?utm_source=axios&utm_medium=readme_sponsorlist&utm_campaign=sponsorship"
|
|
230
|
+
target="_blank"
|
|
231
|
+
><b>poprey.com</b></a
|
|
232
|
+
>
|
|
233
|
+
</p>
|
|
234
|
+
</td>
|
|
235
|
+
</tr>
|
|
236
|
+
<tr width="33.333333333333336%">
|
|
237
|
+
<td align="center" width="33.333333333333336%">
|
|
238
|
+
<a
|
|
239
|
+
href="https://buzzoid.com/buy-instagram-followers/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship"
|
|
240
|
+
style="padding: 10px; display: inline-block"
|
|
241
|
+
target="_blank"
|
|
242
|
+
>
|
|
243
|
+
<img
|
|
244
|
+
width="71px"
|
|
245
|
+
height="70px"
|
|
246
|
+
src="https://images.opencollective.com/buzzoid-buy-instagram-followers/56a09fe/logo.png"
|
|
247
|
+
alt="Buzzoid"
|
|
248
|
+
/>
|
|
249
|
+
</a>
|
|
250
|
+
<p
|
|
251
|
+
align="center"
|
|
252
|
+
>
|
|
253
|
+
A lightweight open-source API Development, Testing & Mocking
|
|
254
|
+
platform
|
|
255
|
+
</p>
|
|
256
|
+
<p align="center">
|
|
257
|
+
<a
|
|
258
|
+
href="https://buzzoid.com/buy-instagram-followers/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship"
|
|
259
|
+
target="_blank"
|
|
260
|
+
><b>buzzoid.com</b></a
|
|
261
|
+
>
|
|
262
|
+
</p>
|
|
263
|
+
</td>
|
|
264
|
+
<td align="center" width="33.333333333333336%">
|
|
265
|
+
<a
|
|
266
|
+
href="https://opencollective.com/axios/contribute"
|
|
267
|
+
target="_blank"
|
|
268
|
+
>💜 Become a sponsor</a
|
|
269
|
+
>
|
|
270
|
+
</td>
|
|
271
|
+
<td align="center" width="33.333333333333336%">
|
|
272
|
+
<a
|
|
273
|
+
href="https://opencollective.com/axios/contribute"
|
|
274
|
+
target="_blank"
|
|
275
|
+
>💜 Become a sponsor</a
|
|
276
|
+
>
|
|
277
|
+
</td>
|
|
278
|
+
</tr>
|
|
279
|
+
</table>
|
|
280
|
+
|
|
16
281
|
|
|
17
282
|
<!--<div>marker</div>-->
|
|
18
283
|
|
|
19
284
|
<br><br>
|
|
20
285
|
|
|
21
286
|
<div align="center">
|
|
22
|
-
<a href="https://axios
|
|
287
|
+
<a href="https://axios.rest"><img src="https://axios.rest/logo.svg" alt="Axios" /></a><br>
|
|
23
288
|
</div>
|
|
24
289
|
|
|
25
290
|
<p align="center">Promise based HTTP client for the browser and node.js</p>
|
|
26
291
|
|
|
27
292
|
<p align="center">
|
|
28
|
-
<a href="https://axios
|
|
29
|
-
<a href="https://axios
|
|
293
|
+
<a href="https://axios.rest/"><b>Website</b></a> •
|
|
294
|
+
<a href="https://axios.rest/pages/getting-started/first-steps.html"><b>Documentation</b></a>
|
|
30
295
|
</p>
|
|
31
296
|
|
|
32
297
|
<div align="center">
|
|
@@ -41,7 +306,6 @@
|
|
|
41
306
|
[](https://npm-stat.com/charts.html?package=axios)
|
|
42
307
|
[](https://gitter.im/mzabriskie/axios)
|
|
43
308
|
[](https://www.codetriage.com/axios/axios)
|
|
44
|
-
[](https://snyk.io/test/npm/axios)
|
|
45
309
|
[](CONTRIBUTORS.md)
|
|
46
310
|
|
|
47
311
|
</div>
|
|
@@ -87,11 +351,13 @@
|
|
|
87
351
|
- [🔥 Fetch adapter](#-fetch-adapter)
|
|
88
352
|
- [🔥 Custom fetch](#-custom-fetch)
|
|
89
353
|
- [🔥 Using with Tauri](#-using-with-tauri)
|
|
90
|
-
- [🔥 Using with SvelteKit](#-using-with-sveltekit
|
|
354
|
+
- [🔥 Using with SvelteKit](#-using-with-sveltekit)
|
|
91
355
|
- [🔥 HTTP2](#-http2)
|
|
92
356
|
- [Semver](#semver)
|
|
93
357
|
- [Promises](#promises)
|
|
94
358
|
- [TypeScript](#typescript)
|
|
359
|
+
- [Contributing](#contributing)
|
|
360
|
+
- [Local setup](#local-setup)
|
|
95
361
|
- [Resources](#resources)
|
|
96
362
|
- [Credits](#credits)
|
|
97
363
|
- [License](#license)
|
|
@@ -127,12 +393,6 @@ Using npm:
|
|
|
127
393
|
$ npm install axios
|
|
128
394
|
```
|
|
129
395
|
|
|
130
|
-
Using bower:
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
$ bower install axios
|
|
134
|
-
```
|
|
135
|
-
|
|
136
396
|
Using yarn:
|
|
137
397
|
|
|
138
398
|
```bash
|
|
@@ -154,36 +414,36 @@ $ bun add axios
|
|
|
154
414
|
Once the package is installed, you can import the library using `import` or `require` approach:
|
|
155
415
|
|
|
156
416
|
```js
|
|
157
|
-
import axios, { isCancel, AxiosError } from
|
|
417
|
+
import axios, { isCancel, AxiosError } from 'axios';
|
|
158
418
|
```
|
|
159
419
|
|
|
160
420
|
You can also use the default export, since the named export is just a re-export from the Axios factory:
|
|
161
421
|
|
|
162
422
|
```js
|
|
163
|
-
import axios from
|
|
423
|
+
import axios from 'axios';
|
|
164
424
|
|
|
165
|
-
console.log(axios.isCancel(
|
|
425
|
+
console.log(axios.isCancel('something'));
|
|
166
426
|
```
|
|
167
427
|
|
|
168
428
|
If you use `require` for importing, **only the default export is available**:
|
|
169
429
|
|
|
170
430
|
```js
|
|
171
|
-
const axios = require(
|
|
431
|
+
const axios = require('axios');
|
|
172
432
|
|
|
173
|
-
console.log(axios.isCancel(
|
|
433
|
+
console.log(axios.isCancel('something'));
|
|
174
434
|
```
|
|
175
435
|
|
|
176
436
|
For some bundlers and some ES6 linters you may need to do the following:
|
|
177
437
|
|
|
178
438
|
```js
|
|
179
|
-
import { default as axios } from
|
|
439
|
+
import { default as axios } from 'axios';
|
|
180
440
|
```
|
|
181
441
|
|
|
182
442
|
For cases where something went wrong when trying to import a module into a custom or legacy environment,
|
|
183
443
|
you can try importing the module package directly:
|
|
184
444
|
|
|
185
445
|
```js
|
|
186
|
-
const axios = require(
|
|
446
|
+
const axios = require('axios/dist/browser/axios.cjs'); // browser commonJS bundle (ES2017)
|
|
187
447
|
// const axios = require('axios/dist/node/axios.cjs'); // node commonJS bundle (ES2017)
|
|
188
448
|
```
|
|
189
449
|
|
|
@@ -204,11 +464,11 @@ Using unpkg CDN:
|
|
|
204
464
|
## Example
|
|
205
465
|
|
|
206
466
|
```js
|
|
207
|
-
import axios from
|
|
467
|
+
import axios from 'axios';
|
|
208
468
|
//const axios = require('axios'); // legacy way
|
|
209
469
|
|
|
210
470
|
try {
|
|
211
|
-
const response = await axios.get(
|
|
471
|
+
const response = await axios.get('/user?ID=12345');
|
|
212
472
|
console.log(response);
|
|
213
473
|
} catch (error) {
|
|
214
474
|
console.error(error);
|
|
@@ -216,10 +476,11 @@ try {
|
|
|
216
476
|
|
|
217
477
|
// Optionally the request above could also be done as
|
|
218
478
|
axios
|
|
219
|
-
.get(
|
|
479
|
+
.get('/user', {
|
|
220
480
|
params: {
|
|
221
481
|
ID: 12345,
|
|
222
482
|
},
|
|
483
|
+
timeout: 5000, // 5 seconds — see "Handling Timeouts" below for matching error handling
|
|
223
484
|
})
|
|
224
485
|
.then(function (response) {
|
|
225
486
|
console.log(response);
|
|
@@ -234,7 +495,7 @@ axios
|
|
|
234
495
|
// Want to use async/await? Add the `async` keyword to your outer function/method.
|
|
235
496
|
async function getUser() {
|
|
236
497
|
try {
|
|
237
|
-
const response = await axios.get(
|
|
498
|
+
const response = await axios.get('/user?ID=12345');
|
|
238
499
|
console.log(response);
|
|
239
500
|
} catch (error) {
|
|
240
501
|
console.error(error);
|
|
@@ -242,15 +503,18 @@ async function getUser() {
|
|
|
242
503
|
}
|
|
243
504
|
```
|
|
244
505
|
|
|
506
|
+
> **Note**: Set a `timeout` in production — without one, a stalled request can hang
|
|
507
|
+
> indefinitely. See [Handling Timeouts](#handling-timeouts) for the matching error handling.
|
|
508
|
+
|
|
245
509
|
> **Note**: `async/await` is part of ECMAScript 2017 and is not supported in Internet
|
|
246
510
|
> Explorer and older browsers, so use with caution.
|
|
247
511
|
|
|
248
512
|
Performing a `POST` request
|
|
249
513
|
|
|
250
514
|
```js
|
|
251
|
-
const response = await axios.post(
|
|
252
|
-
firstName:
|
|
253
|
-
lastName:
|
|
515
|
+
const response = await axios.post('/user', {
|
|
516
|
+
firstName: 'Fred',
|
|
517
|
+
lastName: 'Flintstone',
|
|
254
518
|
});
|
|
255
519
|
console.log(response);
|
|
256
520
|
```
|
|
@@ -259,11 +523,11 @@ Performing multiple concurrent requests
|
|
|
259
523
|
|
|
260
524
|
```js
|
|
261
525
|
function getUserAccount() {
|
|
262
|
-
return axios.get(
|
|
526
|
+
return axios.get('/user/12345');
|
|
263
527
|
}
|
|
264
528
|
|
|
265
529
|
function getUserPermissions() {
|
|
266
|
-
return axios.get(
|
|
530
|
+
return axios.get('/user/12345/permissions');
|
|
267
531
|
}
|
|
268
532
|
|
|
269
533
|
Promise.all([getUserAccount(), getUserPermissions()]).then(function (results) {
|
|
@@ -281,11 +545,11 @@ Requests can be made by passing the relevant config to `axios`.
|
|
|
281
545
|
```js
|
|
282
546
|
// Send a POST request
|
|
283
547
|
axios({
|
|
284
|
-
method:
|
|
285
|
-
url:
|
|
548
|
+
method: 'post',
|
|
549
|
+
url: '/user/12345',
|
|
286
550
|
data: {
|
|
287
|
-
firstName:
|
|
288
|
-
lastName:
|
|
551
|
+
firstName: 'Fred',
|
|
552
|
+
lastName: 'Flintstone',
|
|
289
553
|
},
|
|
290
554
|
});
|
|
291
555
|
```
|
|
@@ -293,18 +557,18 @@ axios({
|
|
|
293
557
|
```js
|
|
294
558
|
// GET request for remote image in node.js
|
|
295
559
|
const response = await axios({
|
|
296
|
-
method:
|
|
297
|
-
url:
|
|
298
|
-
responseType:
|
|
560
|
+
method: 'get',
|
|
561
|
+
url: 'https://bit.ly/2mTM3nY',
|
|
562
|
+
responseType: 'stream',
|
|
299
563
|
});
|
|
300
|
-
response.data.pipe(fs.createWriteStream(
|
|
564
|
+
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'));
|
|
301
565
|
```
|
|
302
566
|
|
|
303
567
|
##### axios(url[, config])
|
|
304
568
|
|
|
305
569
|
```js
|
|
306
570
|
// Send a GET request (default method)
|
|
307
|
-
axios(
|
|
571
|
+
axios('/user/12345');
|
|
308
572
|
```
|
|
309
573
|
|
|
310
574
|
### Request method aliases
|
|
@@ -348,9 +612,9 @@ You can create a new instance of axios with a custom config.
|
|
|
348
612
|
|
|
349
613
|
```js
|
|
350
614
|
const instance = axios.create({
|
|
351
|
-
baseURL:
|
|
615
|
+
baseURL: 'https://some-domain.com/api/',
|
|
352
616
|
timeout: 1000,
|
|
353
|
-
headers: {
|
|
617
|
+
headers: { 'X-Custom-Header': 'foobar' },
|
|
354
618
|
});
|
|
355
619
|
```
|
|
356
620
|
|
|
@@ -378,6 +642,19 @@ The available instance methods are listed below. The specified config will be me
|
|
|
378
642
|
|
|
379
643
|
## Request Config
|
|
380
644
|
|
|
645
|
+
### ⚠️ Security notice: decompression-bomb protection is opt-in
|
|
646
|
+
|
|
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.
|
|
648
|
+
|
|
649
|
+
If you call servers you do not fully trust, **set a cap**:
|
|
650
|
+
|
|
651
|
+
```js
|
|
652
|
+
axios.defaults.maxContentLength = 10 * 1024 * 1024; // 10 MB
|
|
653
|
+
axios.defaults.maxBodyLength = 10 * 1024 * 1024;
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
See the [security guide](https://axios.rest/pages/misc/security.html) for details.
|
|
657
|
+
|
|
381
658
|
These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified.
|
|
382
659
|
|
|
383
660
|
```js
|
|
@@ -417,6 +694,27 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
417
694
|
return data;
|
|
418
695
|
}],
|
|
419
696
|
|
|
697
|
+
// `parseReviver` is an optional function that will be passed as the
|
|
698
|
+
// second argument (reviver) to JSON.parse()
|
|
699
|
+
parseReviver: function (key, value, context) {
|
|
700
|
+
// In modern environments, context.source provides the raw JSON string
|
|
701
|
+
// allowing for precision-safe parsing of BigInt
|
|
702
|
+
if (typeof value === 'number' && context?.source) {
|
|
703
|
+
const isInteger = Number.isInteger(value);
|
|
704
|
+
const isUnsafe = !Number.isSafeInteger(value);
|
|
705
|
+
const isValidIntegerString = /^-?\d+$/.test(context.source);
|
|
706
|
+
|
|
707
|
+
if (isInteger && isUnsafe && isValidIntegerString) {
|
|
708
|
+
try {
|
|
709
|
+
return BigInt(context.source);
|
|
710
|
+
} catch {
|
|
711
|
+
// Fallback: return original value if parsing fails
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return value;
|
|
716
|
+
},
|
|
717
|
+
|
|
420
718
|
// `headers` are custom headers to be sent
|
|
421
719
|
headers: {'X-Requested-With': 'XMLHttpRequest'},
|
|
422
720
|
|
|
@@ -436,7 +734,12 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
436
734
|
serialize?: (params: Record<string, any>, options?: ParamsSerializerOptions ),
|
|
437
735
|
|
|
438
736
|
// Configuration for formatting array indexes in the params.
|
|
439
|
-
indexes: false // Three available options: (1) indexes: null (leads to no brackets), (2) (default) indexes: false (leads to empty brackets), (3) indexes: true (leads to brackets with indexes).
|
|
737
|
+
indexes: false, // Three available options: (1) indexes: null (leads to no brackets), (2) (default) indexes: false (leads to empty brackets), (3) indexes: true (leads to brackets with indexes).
|
|
738
|
+
|
|
739
|
+
// Maximum object nesting depth when serializing params. Payloads deeper than this throw an
|
|
740
|
+
// AxiosError with code ERR_FORM_DATA_DEPTH_EXCEEDED. Default: 100. Set to Infinity to disable.
|
|
741
|
+
maxDepth: 100
|
|
742
|
+
|
|
440
743
|
},
|
|
441
744
|
|
|
442
745
|
// `data` is the data to be sent as the request body
|
|
@@ -449,6 +752,11 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
449
752
|
firstName: 'Fred'
|
|
450
753
|
},
|
|
451
754
|
|
|
755
|
+
// `formDataHeaderPolicy` controls how node.js FormData#getHeaders() is copied.
|
|
756
|
+
// 'legacy' (default) copies all returned headers for v1 compatibility.
|
|
757
|
+
// 'content-only' copies only Content-Type and Content-Length.
|
|
758
|
+
formDataHeaderPolicy: 'legacy',
|
|
759
|
+
|
|
452
760
|
// syntax alternative to send data into the body
|
|
453
761
|
// method post
|
|
454
762
|
// only the value is sent, not the key
|
|
@@ -543,6 +851,10 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
543
851
|
// `maxBodyLength` (Node only option) defines the max size of the http request content in bytes allowed
|
|
544
852
|
maxBodyLength: 2000,
|
|
545
853
|
|
|
854
|
+
// `redact` masks matching config keys when AxiosError#toJSON() is called.
|
|
855
|
+
// Matching is case-insensitive and recursive. It does not change the request.
|
|
856
|
+
redact: ['authorization', 'password'],
|
|
857
|
+
|
|
546
858
|
// `validateStatus` defines whether to resolve or reject the promise for a given
|
|
547
859
|
// HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
|
|
548
860
|
// or `undefined`), the promise will be resolved; otherwise, the promise will be
|
|
@@ -586,8 +898,19 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
586
898
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
|
|
587
899
|
// Only either `socketPath` or `proxy` can be specified.
|
|
588
900
|
// If both are specified, `socketPath` is used.
|
|
901
|
+
//
|
|
902
|
+
// Security: when `socketPath` is set, hostname/port of the URL are ignored,
|
|
903
|
+
// which bypasses hostname-based SSRF protections. Never derive `socketPath`
|
|
904
|
+
// from untrusted input. Use `allowedSocketPaths` (below) to restrict accepted
|
|
905
|
+
// socket paths for defense-in-depth.
|
|
589
906
|
socketPath: null, // default
|
|
590
907
|
|
|
908
|
+
// `allowedSocketPaths` restricts which `socketPath` values are accepted.
|
|
909
|
+
// Accepts a string or array of strings. Entries and the incoming socketPath
|
|
910
|
+
// are compared after path.resolve(). A mismatch throws AxiosError with code
|
|
911
|
+
// `ERR_BAD_OPTION_VALUE`. When null/undefined, no restriction is applied.
|
|
912
|
+
allowedSocketPaths: null, // default
|
|
913
|
+
|
|
591
914
|
// `transport` determines the transport method that will be used to make the request.
|
|
592
915
|
// If defined, it will be used. Otherwise, if `maxRedirects` is 0,
|
|
593
916
|
// the default `http` or `https` library will be used, depending on the protocol specified in `protocol`.
|
|
@@ -614,6 +937,12 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
614
937
|
// This will set a `Proxy-Authorization` header, overwriting any existing
|
|
615
938
|
// `Proxy-Authorization` custom headers you have set using `headers`.
|
|
616
939
|
// If the proxy server uses HTTPS, then you must set the protocol to `https`.
|
|
940
|
+
// A user-supplied `Host` header in `headers` is preserved when forwarding
|
|
941
|
+
// through a proxy (case-insensitive match on `host`/`Host`/`HOST`); this
|
|
942
|
+
// lets you target a virtual host that differs from the request URL — for
|
|
943
|
+
// example, hitting `127.0.0.1:4000` while having the proxy treat the
|
|
944
|
+
// request as `example.com`. If no `Host` header is supplied, axios
|
|
945
|
+
// defaults it to the request URL's `hostname:port` as before.
|
|
617
946
|
proxy: {
|
|
618
947
|
protocol: 'https',
|
|
619
948
|
host: '127.0.0.1',
|
|
@@ -679,6 +1008,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
679
1008
|
dots: boolean; // use dots instead of brackets format
|
|
680
1009
|
metaTokens: boolean; // keep special endings like {} in parameter key
|
|
681
1010
|
indexes: boolean; // array indexes format null - no brackets, false - empty brackets, true - brackets with indexes
|
|
1011
|
+
maxDepth: 100; // maximum object nesting depth; throws AxiosError (ERR_FORM_DATA_DEPTH_EXCEEDED) if exceeded. Set to Infinity to disable.
|
|
682
1012
|
},
|
|
683
1013
|
|
|
684
1014
|
// http adapter only (node.js)
|
|
@@ -688,6 +1018,26 @@ These are the available config options for making requests. Only the `url` is re
|
|
|
688
1018
|
]
|
|
689
1019
|
}
|
|
690
1020
|
```
|
|
1021
|
+
|
|
1022
|
+
### Strict RFC 3986 percent-encoding for query params
|
|
1023
|
+
|
|
1024
|
+
By default, axios decodes `%3A`, `%24`, `%2C` and `%20` back to `:`, `$`, `,` and `+` for readability (the `+` follows the `application/x-www-form-urlencoded` convention for spaces in query strings). These characters are valid in a query component under [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986#section-3.4), so the default output is correct, but some backends require strict percent-encoding and reject the readable form.
|
|
1025
|
+
|
|
1026
|
+
Override the default encoder via `paramsSerializer.encode`:
|
|
1027
|
+
|
|
1028
|
+
```js
|
|
1029
|
+
// Per-request: emit strict RFC 3986 percent-encoding for query values
|
|
1030
|
+
axios.get('/foo', {
|
|
1031
|
+
params: { filter: JSON.stringify({ startedAt: '2026-01-23' }) },
|
|
1032
|
+
paramsSerializer: { encode: encodeURIComponent }
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
// Or set it on the instance defaults
|
|
1036
|
+
const client = axios.create({
|
|
1037
|
+
paramsSerializer: { encode: encodeURIComponent }
|
|
1038
|
+
});
|
|
1039
|
+
```
|
|
1040
|
+
|
|
691
1041
|
## 🔥 HTTP/2 Support
|
|
692
1042
|
|
|
693
1043
|
Axios has experimental HTTP/2 support available via the Node.js HTTP adapter.
|
|
@@ -731,7 +1081,7 @@ The response to a request contains the following information.
|
|
|
731
1081
|
When using `then`, you will receive the response as follows:
|
|
732
1082
|
|
|
733
1083
|
```js
|
|
734
|
-
const response = await axios.get(
|
|
1084
|
+
const response = await axios.get('/user/12345');
|
|
735
1085
|
console.log(response.data);
|
|
736
1086
|
console.log(response.status);
|
|
737
1087
|
console.log(response.statusText);
|
|
@@ -748,14 +1098,13 @@ You can specify config defaults that will be applied to every request.
|
|
|
748
1098
|
### Global axios defaults
|
|
749
1099
|
|
|
750
1100
|
```js
|
|
751
|
-
axios.defaults.baseURL =
|
|
1101
|
+
axios.defaults.baseURL = 'https://api.example.com';
|
|
752
1102
|
|
|
753
1103
|
// Important: If axios is used with multiple domains, the AUTH_TOKEN will be sent to all of them.
|
|
754
1104
|
// See below for an example using Custom instance defaults instead.
|
|
755
|
-
axios.defaults.headers.common[
|
|
1105
|
+
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
756
1106
|
|
|
757
|
-
axios.defaults.headers.post[
|
|
758
|
-
"application/x-www-form-urlencoded";
|
|
1107
|
+
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
759
1108
|
```
|
|
760
1109
|
|
|
761
1110
|
### Custom instance defaults
|
|
@@ -763,11 +1112,11 @@ axios.defaults.headers.post["Content-Type"] =
|
|
|
763
1112
|
```js
|
|
764
1113
|
// Set config defaults when creating the instance
|
|
765
1114
|
const instance = axios.create({
|
|
766
|
-
baseURL:
|
|
1115
|
+
baseURL: 'https://api.example.com',
|
|
767
1116
|
});
|
|
768
1117
|
|
|
769
1118
|
// Alter defaults after instance has been created
|
|
770
|
-
instance.defaults.headers.common[
|
|
1119
|
+
instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
|
771
1120
|
```
|
|
772
1121
|
|
|
773
1122
|
### Config order of precedence
|
|
@@ -784,7 +1133,7 @@ const instance = axios.create();
|
|
|
784
1133
|
instance.defaults.timeout = 2500;
|
|
785
1134
|
|
|
786
1135
|
// Override timeout for this request as it's known to take a long time
|
|
787
|
-
instance.get(
|
|
1136
|
+
instance.get('/longRequest', {
|
|
788
1137
|
timeout: 5000,
|
|
789
1138
|
});
|
|
790
1139
|
```
|
|
@@ -806,7 +1155,7 @@ instance.interceptors.request.use(
|
|
|
806
1155
|
function (error) {
|
|
807
1156
|
// Do something with the request error
|
|
808
1157
|
return Promise.reject(error);
|
|
809
|
-
}
|
|
1158
|
+
}
|
|
810
1159
|
);
|
|
811
1160
|
|
|
812
1161
|
// Add a response interceptor
|
|
@@ -820,7 +1169,7 @@ instance.interceptors.response.use(
|
|
|
820
1169
|
// Any status codes that fall outside the range of 2xx cause this function to trigger
|
|
821
1170
|
// Do something with response error
|
|
822
1171
|
return Promise.reject(error);
|
|
823
|
-
}
|
|
1172
|
+
}
|
|
824
1173
|
);
|
|
825
1174
|
```
|
|
826
1175
|
|
|
@@ -865,11 +1214,11 @@ to the options object that will tell axios to run the code synchronously and avo
|
|
|
865
1214
|
```js
|
|
866
1215
|
axios.interceptors.request.use(
|
|
867
1216
|
function (config) {
|
|
868
|
-
config.headers.test =
|
|
1217
|
+
config.headers.test = 'I am only a header!';
|
|
869
1218
|
return config;
|
|
870
1219
|
},
|
|
871
1220
|
null,
|
|
872
|
-
{ synchronous: true }
|
|
1221
|
+
{ synchronous: true }
|
|
873
1222
|
);
|
|
874
1223
|
```
|
|
875
1224
|
|
|
@@ -881,15 +1230,15 @@ asynchronous request interceptor that only needs to run at certain times.
|
|
|
881
1230
|
|
|
882
1231
|
```js
|
|
883
1232
|
function onGetCall(config) {
|
|
884
|
-
return config.method ===
|
|
1233
|
+
return config.method === 'get';
|
|
885
1234
|
}
|
|
886
1235
|
axios.interceptors.request.use(
|
|
887
1236
|
function (config) {
|
|
888
|
-
config.headers.test =
|
|
1237
|
+
config.headers.test = 'special get headers';
|
|
889
1238
|
return config;
|
|
890
1239
|
},
|
|
891
1240
|
null,
|
|
892
|
-
{ runWhen: onGetCall }
|
|
1241
|
+
{ runWhen: onGetCall }
|
|
893
1242
|
);
|
|
894
1243
|
```
|
|
895
1244
|
|
|
@@ -913,12 +1262,12 @@ const interceptor = (id) => (base) => {
|
|
|
913
1262
|
return base;
|
|
914
1263
|
};
|
|
915
1264
|
|
|
916
|
-
instance.interceptors.request.use(interceptor(
|
|
917
|
-
instance.interceptors.request.use(interceptor(
|
|
918
|
-
instance.interceptors.request.use(interceptor(
|
|
919
|
-
instance.interceptors.response.use(interceptor(
|
|
920
|
-
instance.interceptors.response.use(interceptor(
|
|
921
|
-
instance.interceptors.response.use(interceptor(
|
|
1265
|
+
instance.interceptors.request.use(interceptor('Request Interceptor 1'));
|
|
1266
|
+
instance.interceptors.request.use(interceptor('Request Interceptor 2'));
|
|
1267
|
+
instance.interceptors.request.use(interceptor('Request Interceptor 3'));
|
|
1268
|
+
instance.interceptors.response.use(interceptor('Response Interceptor 1'));
|
|
1269
|
+
instance.interceptors.response.use(interceptor('Response Interceptor 2'));
|
|
1270
|
+
instance.interceptors.response.use(interceptor('Response Interceptor 3'));
|
|
922
1271
|
|
|
923
1272
|
// Console output:
|
|
924
1273
|
// Request Interceptor 3
|
|
@@ -982,7 +1331,7 @@ Below is a list of potential axios identified error:
|
|
|
982
1331
|
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.
|
|
983
1332
|
|
|
984
1333
|
```js
|
|
985
|
-
axios.get(
|
|
1334
|
+
axios.get('/user/12345').catch(function (error) {
|
|
986
1335
|
if (error.response) {
|
|
987
1336
|
// The request was made and the server responded with a status code
|
|
988
1337
|
// that falls out of the range of 2xx
|
|
@@ -996,7 +1345,7 @@ axios.get("/user/12345").catch(function (error) {
|
|
|
996
1345
|
console.log(error.request);
|
|
997
1346
|
} else {
|
|
998
1347
|
// Something happened in setting up the request that triggered an Error
|
|
999
|
-
console.log(
|
|
1348
|
+
console.log('Error', error.message);
|
|
1000
1349
|
}
|
|
1001
1350
|
console.log(error.config);
|
|
1002
1351
|
});
|
|
@@ -1005,7 +1354,7 @@ axios.get("/user/12345").catch(function (error) {
|
|
|
1005
1354
|
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.
|
|
1006
1355
|
|
|
1007
1356
|
```js
|
|
1008
|
-
axios.get(
|
|
1357
|
+
axios.get('/user/12345', {
|
|
1009
1358
|
validateStatus: function (status) {
|
|
1010
1359
|
return status < 500; // Resolve only if the status code is less than 500
|
|
1011
1360
|
},
|
|
@@ -1015,17 +1364,28 @@ axios.get("/user/12345", {
|
|
|
1015
1364
|
Using `toJSON` you get an object with more information about the HTTP error.
|
|
1016
1365
|
|
|
1017
1366
|
```js
|
|
1018
|
-
axios.get(
|
|
1367
|
+
axios.get('/user/12345').catch(function (error) {
|
|
1019
1368
|
console.log(error.toJSON());
|
|
1020
1369
|
});
|
|
1021
1370
|
```
|
|
1022
1371
|
|
|
1372
|
+
To avoid logging secrets from `error.config`, pass a `redact` array in the request config. Matching config keys are masked case-insensitively at any depth when `AxiosError#toJSON()` is called.
|
|
1373
|
+
|
|
1374
|
+
```js
|
|
1375
|
+
axios.get('/user/12345', {
|
|
1376
|
+
headers: { Authorization: 'Bearer token' },
|
|
1377
|
+
redact: ['authorization']
|
|
1378
|
+
}).catch(function (error) {
|
|
1379
|
+
console.log(error.toJSON().config.headers.Authorization); // [REDACTED ****]
|
|
1380
|
+
});
|
|
1381
|
+
```
|
|
1382
|
+
|
|
1023
1383
|
## Handling Timeouts
|
|
1024
1384
|
|
|
1025
1385
|
```js
|
|
1026
1386
|
async function fetchWithTimeout() {
|
|
1027
1387
|
try {
|
|
1028
|
-
const response = await axios.get(
|
|
1388
|
+
const response = await axios.get('https://example.com/data', {
|
|
1029
1389
|
timeout: 5000, // 5 seconds
|
|
1030
1390
|
transitional: {
|
|
1031
1391
|
// set to true if you prefer ETIMEDOUT over ECONNABORTED
|
|
@@ -1033,19 +1393,19 @@ async function fetchWithTimeout() {
|
|
|
1033
1393
|
},
|
|
1034
1394
|
});
|
|
1035
1395
|
|
|
1036
|
-
console.log(
|
|
1396
|
+
console.log('Response:', response.data);
|
|
1037
1397
|
} catch (error) {
|
|
1038
1398
|
if (axios.isAxiosError(error)) {
|
|
1039
|
-
if (error.code ===
|
|
1040
|
-
console.error(
|
|
1399
|
+
if (error.code === 'ECONNABORTED' || error.code === 'ETIMEDOUT') {
|
|
1400
|
+
console.error('Request timed out. Please try again.');
|
|
1041
1401
|
return;
|
|
1042
1402
|
}
|
|
1043
1403
|
|
|
1044
|
-
console.error(
|
|
1404
|
+
console.error('Axios error:', error.message);
|
|
1045
1405
|
return;
|
|
1046
1406
|
}
|
|
1047
1407
|
|
|
1048
|
-
console.error(
|
|
1408
|
+
console.error('Unexpected error:', error);
|
|
1049
1409
|
}
|
|
1050
1410
|
}
|
|
1051
1411
|
```
|
|
@@ -1060,7 +1420,7 @@ Starting from `v0.22.0` Axios supports AbortController to cancel requests in a f
|
|
|
1060
1420
|
const controller = new AbortController();
|
|
1061
1421
|
|
|
1062
1422
|
axios
|
|
1063
|
-
.get(
|
|
1423
|
+
.get('/foo/bar', {
|
|
1064
1424
|
signal: controller.signal,
|
|
1065
1425
|
})
|
|
1066
1426
|
.then(function (response) {
|
|
@@ -1085,29 +1445,29 @@ const CancelToken = axios.CancelToken;
|
|
|
1085
1445
|
const source = CancelToken.source();
|
|
1086
1446
|
|
|
1087
1447
|
axios
|
|
1088
|
-
.get(
|
|
1448
|
+
.get('/user/12345', {
|
|
1089
1449
|
cancelToken: source.token,
|
|
1090
1450
|
})
|
|
1091
1451
|
.catch(function (thrown) {
|
|
1092
1452
|
if (axios.isCancel(thrown)) {
|
|
1093
|
-
console.log(
|
|
1453
|
+
console.log('Request canceled', thrown.message);
|
|
1094
1454
|
} else {
|
|
1095
1455
|
// handle error
|
|
1096
1456
|
}
|
|
1097
1457
|
});
|
|
1098
1458
|
|
|
1099
1459
|
axios.post(
|
|
1100
|
-
|
|
1460
|
+
'/user/12345',
|
|
1101
1461
|
{
|
|
1102
|
-
name:
|
|
1462
|
+
name: 'new name',
|
|
1103
1463
|
},
|
|
1104
1464
|
{
|
|
1105
1465
|
cancelToken: source.token,
|
|
1106
|
-
}
|
|
1466
|
+
}
|
|
1107
1467
|
);
|
|
1108
1468
|
|
|
1109
1469
|
// cancel the request (the message parameter is optional)
|
|
1110
|
-
source.cancel(
|
|
1470
|
+
source.cancel('Operation canceled by the user.');
|
|
1111
1471
|
```
|
|
1112
1472
|
|
|
1113
1473
|
You can also create a cancel token by passing an executor function to the `CancelToken` constructor:
|
|
@@ -1116,7 +1476,7 @@ You can also create a cancel token by passing an executor function to the `Cance
|
|
|
1116
1476
|
const CancelToken = axios.CancelToken;
|
|
1117
1477
|
let cancel;
|
|
1118
1478
|
|
|
1119
|
-
axios.get(
|
|
1479
|
+
axios.get('/user/12345', {
|
|
1120
1480
|
cancelToken: new CancelToken(function executor(c) {
|
|
1121
1481
|
// An executor function receives a cancel function as a parameter
|
|
1122
1482
|
cancel = c;
|
|
@@ -1139,9 +1499,9 @@ cancel();
|
|
|
1139
1499
|
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).
|
|
1140
1500
|
|
|
1141
1501
|
```js
|
|
1142
|
-
const params = new URLSearchParams({ foo:
|
|
1143
|
-
params.append(
|
|
1144
|
-
axios.post(
|
|
1502
|
+
const params = new URLSearchParams({ foo: 'bar' });
|
|
1503
|
+
params.append('extraparam', 'value');
|
|
1504
|
+
axios.post('/foo', params);
|
|
1145
1505
|
```
|
|
1146
1506
|
|
|
1147
1507
|
### Query string (Older browsers)
|
|
@@ -1151,18 +1511,18 @@ For compatibility with very old browsers, there is a [polyfill](https://github.c
|
|
|
1151
1511
|
Alternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library:
|
|
1152
1512
|
|
|
1153
1513
|
```js
|
|
1154
|
-
const qs = require(
|
|
1155
|
-
axios.post(
|
|
1514
|
+
const qs = require('qs');
|
|
1515
|
+
axios.post('/foo', qs.stringify({ bar: 123 }));
|
|
1156
1516
|
```
|
|
1157
1517
|
|
|
1158
1518
|
Or in another way (ES6),
|
|
1159
1519
|
|
|
1160
1520
|
```js
|
|
1161
|
-
import qs from
|
|
1521
|
+
import qs from 'qs';
|
|
1162
1522
|
const data = { bar: 123 };
|
|
1163
1523
|
const options = {
|
|
1164
|
-
method:
|
|
1165
|
-
headers: {
|
|
1524
|
+
method: 'POST',
|
|
1525
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
1166
1526
|
data: qs.stringify(data),
|
|
1167
1527
|
url,
|
|
1168
1528
|
};
|
|
@@ -1174,8 +1534,8 @@ axios(options);
|
|
|
1174
1534
|
For older Node.js engines, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
|
|
1175
1535
|
|
|
1176
1536
|
```js
|
|
1177
|
-
const querystring = require(
|
|
1178
|
-
axios.post(
|
|
1537
|
+
const querystring = require('querystring');
|
|
1538
|
+
axios.post('https://something.com/', querystring.stringify({ foo: 'bar' }));
|
|
1179
1539
|
```
|
|
1180
1540
|
|
|
1181
1541
|
You can also use the [`qs`](https://github.com/ljharb/qs) library.
|
|
@@ -1192,13 +1552,13 @@ const data = {
|
|
|
1192
1552
|
arr: [1, 2, 3],
|
|
1193
1553
|
arr2: [1, [2], 3],
|
|
1194
1554
|
users: [
|
|
1195
|
-
{ name:
|
|
1196
|
-
{ name:
|
|
1555
|
+
{ name: 'Peter', surname: 'Griffin' },
|
|
1556
|
+
{ name: 'Thomas', surname: 'Anderson' },
|
|
1197
1557
|
],
|
|
1198
1558
|
};
|
|
1199
1559
|
|
|
1200
|
-
await axios.postForm(
|
|
1201
|
-
headers: {
|
|
1560
|
+
await axios.postForm('https://postman-echo.com/post', data, {
|
|
1561
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
1202
1562
|
});
|
|
1203
1563
|
```
|
|
1204
1564
|
|
|
@@ -1226,7 +1586,7 @@ const app = express();
|
|
|
1226
1586
|
|
|
1227
1587
|
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
|
|
1228
1588
|
|
|
1229
|
-
app.post(
|
|
1589
|
+
app.post('/', function (req, res, next) {
|
|
1230
1590
|
// echo body as JSON
|
|
1231
1591
|
res.send(JSON.stringify(req.body));
|
|
1232
1592
|
});
|
|
@@ -1243,24 +1603,26 @@ Setting the `Content-Type` header is not required as Axios guesses it based on t
|
|
|
1243
1603
|
|
|
1244
1604
|
```js
|
|
1245
1605
|
const formData = new FormData();
|
|
1246
|
-
formData.append(
|
|
1606
|
+
formData.append('foo', 'bar');
|
|
1247
1607
|
|
|
1248
|
-
axios.post(
|
|
1608
|
+
axios.post('https://httpbin.org/post', formData);
|
|
1249
1609
|
```
|
|
1250
1610
|
|
|
1251
1611
|
In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
|
|
1252
1612
|
|
|
1253
1613
|
```js
|
|
1254
|
-
const FormData = require(
|
|
1614
|
+
const FormData = require('form-data');
|
|
1255
1615
|
|
|
1256
1616
|
const form = new FormData();
|
|
1257
|
-
form.append(
|
|
1258
|
-
form.append(
|
|
1259
|
-
form.append(
|
|
1617
|
+
form.append('my_field', 'my value');
|
|
1618
|
+
form.append('my_buffer', Buffer.alloc(10));
|
|
1619
|
+
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
|
1260
1620
|
|
|
1261
|
-
axios.post(
|
|
1621
|
+
axios.post('https://example.com', form);
|
|
1262
1622
|
```
|
|
1263
1623
|
|
|
1624
|
+
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
|
+
|
|
1264
1626
|
### 🆕 Automatic serialization to FormData
|
|
1265
1627
|
|
|
1266
1628
|
Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
|
|
@@ -1269,17 +1631,17 @@ header is set to `multipart/form-data`.
|
|
|
1269
1631
|
The following request will submit the data in a FormData format (Browser & Node.js):
|
|
1270
1632
|
|
|
1271
1633
|
```js
|
|
1272
|
-
import axios from
|
|
1634
|
+
import axios from 'axios';
|
|
1273
1635
|
|
|
1274
1636
|
axios
|
|
1275
1637
|
.post(
|
|
1276
|
-
|
|
1638
|
+
'https://httpbin.org/post',
|
|
1277
1639
|
{ x: 1 },
|
|
1278
1640
|
{
|
|
1279
1641
|
headers: {
|
|
1280
|
-
|
|
1642
|
+
'Content-Type': 'multipart/form-data',
|
|
1281
1643
|
},
|
|
1282
|
-
}
|
|
1644
|
+
}
|
|
1283
1645
|
)
|
|
1284
1646
|
.then(({ data }) => console.log(data));
|
|
1285
1647
|
```
|
|
@@ -1290,18 +1652,18 @@ You can overload the FormData class by setting the `env.FormData` config variabl
|
|
|
1290
1652
|
but you probably won't need it in most cases:
|
|
1291
1653
|
|
|
1292
1654
|
```js
|
|
1293
|
-
const axios = require(
|
|
1294
|
-
var FormData = require(
|
|
1655
|
+
const axios = require('axios');
|
|
1656
|
+
var FormData = require('form-data');
|
|
1295
1657
|
|
|
1296
1658
|
axios
|
|
1297
1659
|
.post(
|
|
1298
|
-
|
|
1660
|
+
'https://httpbin.org/post',
|
|
1299
1661
|
{ x: 1, buf: Buffer.alloc(10) },
|
|
1300
1662
|
{
|
|
1301
1663
|
headers: {
|
|
1302
|
-
|
|
1664
|
+
'Content-Type': 'multipart/form-data',
|
|
1303
1665
|
},
|
|
1304
|
-
}
|
|
1666
|
+
}
|
|
1305
1667
|
)
|
|
1306
1668
|
.then(({ data }) => console.log(data));
|
|
1307
1669
|
```
|
|
@@ -1327,6 +1689,18 @@ FormData serializer supports additional options via `config.formSerializer: obje
|
|
|
1327
1689
|
- `null` - don't add brackets (`arr: 1`, `arr: 2`, `arr: 3`)
|
|
1328
1690
|
- `false`(default) - add empty brackets (`arr[]: 1`, `arr[]: 2`, `arr[]: 3`)
|
|
1329
1691
|
- `true` - add brackets with indexes (`arr[0]: 1`, `arr[1]: 2`, `arr[2]: 3`)
|
|
1692
|
+
- `maxDepth: number = 100` - maximum object nesting depth the serializer will recurse into. If the
|
|
1693
|
+
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-side applications from DoS
|
|
1695
|
+
attacks via deeply nested payloads. Set to `Infinity` to disable the limit and restore pre-fix behaviour.
|
|
1696
|
+
|
|
1697
|
+
```js
|
|
1698
|
+
// Raise the limit for a schema that genuinely nests deeper than 100 levels:
|
|
1699
|
+
axios.postForm('/api', data, { formSerializer: { maxDepth: 200 } });
|
|
1700
|
+
|
|
1701
|
+
// Same protection applies to params serialization:
|
|
1702
|
+
axios.get('/api', { params: data, paramsSerializer: { maxDepth: 200 } });
|
|
1703
|
+
```
|
|
1330
1704
|
|
|
1331
1705
|
Let's say we have an object like this one:
|
|
1332
1706
|
|
|
@@ -1336,10 +1710,10 @@ const obj = {
|
|
|
1336
1710
|
arr: [1, 2, 3],
|
|
1337
1711
|
arr2: [1, [2], 3],
|
|
1338
1712
|
users: [
|
|
1339
|
-
{ name:
|
|
1340
|
-
{ name:
|
|
1713
|
+
{ name: 'Peter', surname: 'Griffin' },
|
|
1714
|
+
{ name: 'Thomas', surname: 'Anderson' },
|
|
1341
1715
|
],
|
|
1342
|
-
|
|
1716
|
+
'obj2{}': [{ x: 1 }],
|
|
1343
1717
|
};
|
|
1344
1718
|
```
|
|
1345
1719
|
|
|
@@ -1347,18 +1721,18 @@ The following steps will be executed by the Axios serializer internally:
|
|
|
1347
1721
|
|
|
1348
1722
|
```js
|
|
1349
1723
|
const formData = new FormData();
|
|
1350
|
-
formData.append(
|
|
1351
|
-
formData.append(
|
|
1352
|
-
formData.append(
|
|
1353
|
-
formData.append(
|
|
1354
|
-
formData.append(
|
|
1355
|
-
formData.append(
|
|
1356
|
-
formData.append(
|
|
1357
|
-
formData.append(
|
|
1358
|
-
formData.append(
|
|
1359
|
-
formData.append(
|
|
1360
|
-
formData.append(
|
|
1361
|
-
formData.append(
|
|
1724
|
+
formData.append('x', '1');
|
|
1725
|
+
formData.append('arr[]', '1');
|
|
1726
|
+
formData.append('arr[]', '2');
|
|
1727
|
+
formData.append('arr[]', '3');
|
|
1728
|
+
formData.append('arr2[0]', '1');
|
|
1729
|
+
formData.append('arr2[1][0]', '2');
|
|
1730
|
+
formData.append('arr2[2]', '3');
|
|
1731
|
+
formData.append('users[0][name]', 'Peter');
|
|
1732
|
+
formData.append('users[0][surname]', 'Griffin');
|
|
1733
|
+
formData.append('users[1][name]', 'Thomas');
|
|
1734
|
+
formData.append('users[1][surname]', 'Anderson');
|
|
1735
|
+
formData.append('obj2{}', '[{"x":1}]');
|
|
1362
1736
|
```
|
|
1363
1737
|
|
|
1364
1738
|
Axios supports the following shortcut methods: `postForm`, `putForm`, `patchForm`
|
|
@@ -1369,27 +1743,24 @@ which are just the corresponding http methods with the `Content-Type` header pre
|
|
|
1369
1743
|
You can easily submit a single file:
|
|
1370
1744
|
|
|
1371
1745
|
```js
|
|
1372
|
-
await axios.postForm(
|
|
1373
|
-
myVar:
|
|
1374
|
-
file: document.querySelector(
|
|
1746
|
+
await axios.postForm('https://httpbin.org/post', {
|
|
1747
|
+
myVar: 'foo',
|
|
1748
|
+
file: document.querySelector('#fileInput').files[0],
|
|
1375
1749
|
});
|
|
1376
1750
|
```
|
|
1377
1751
|
|
|
1378
1752
|
or multiple files as `multipart/form-data`:
|
|
1379
1753
|
|
|
1380
1754
|
```js
|
|
1381
|
-
await axios.postForm(
|
|
1382
|
-
|
|
1755
|
+
await axios.postForm('https://httpbin.org/post', {
|
|
1756
|
+
'files[]': document.querySelector('#fileInput').files,
|
|
1383
1757
|
});
|
|
1384
1758
|
```
|
|
1385
1759
|
|
|
1386
1760
|
`FileList` object can be passed directly:
|
|
1387
1761
|
|
|
1388
1762
|
```js
|
|
1389
|
-
await axios.postForm(
|
|
1390
|
-
"https://httpbin.org/post",
|
|
1391
|
-
document.querySelector("#fileInput").files,
|
|
1392
|
-
);
|
|
1763
|
+
await axios.postForm('https://httpbin.org/post', document.querySelector('#fileInput').files);
|
|
1393
1764
|
```
|
|
1394
1765
|
|
|
1395
1766
|
All files will be sent with the same field names: `files[]`.
|
|
@@ -1399,24 +1770,17 @@ All files will be sent with the same field names: `files[]`.
|
|
|
1399
1770
|
Pass an HTML Form element as a payload to submit it as `multipart/form-data` content.
|
|
1400
1771
|
|
|
1401
1772
|
```js
|
|
1402
|
-
await axios.postForm(
|
|
1403
|
-
"https://httpbin.org/post",
|
|
1404
|
-
document.querySelector("#htmlForm"),
|
|
1405
|
-
);
|
|
1773
|
+
await axios.postForm('https://httpbin.org/post', document.querySelector('#htmlForm'));
|
|
1406
1774
|
```
|
|
1407
1775
|
|
|
1408
1776
|
`FormData` and `HTMLForm` objects can also be posted as `JSON` by explicitly setting the `Content-Type` header to `application/json`:
|
|
1409
1777
|
|
|
1410
1778
|
```js
|
|
1411
|
-
await axios.post(
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
{
|
|
1415
|
-
headers: {
|
|
1416
|
-
"Content-Type": "application/json",
|
|
1417
|
-
},
|
|
1779
|
+
await axios.post('https://httpbin.org/post', document.querySelector('#htmlForm'), {
|
|
1780
|
+
headers: {
|
|
1781
|
+
'Content-Type': 'application/json',
|
|
1418
1782
|
},
|
|
1419
|
-
);
|
|
1783
|
+
});
|
|
1420
1784
|
```
|
|
1421
1785
|
|
|
1422
1786
|
For example, the Form
|
|
@@ -1503,7 +1867,7 @@ const { data } = await axios.post(SERVER_URL, readableStream, {
|
|
|
1503
1867
|
},
|
|
1504
1868
|
|
|
1505
1869
|
headers: {
|
|
1506
|
-
|
|
1870
|
+
'Content-Length': contentLength,
|
|
1507
1871
|
},
|
|
1508
1872
|
|
|
1509
1873
|
maxRedirects: 0, // avoid buffering the entire stream
|
|
@@ -1524,9 +1888,7 @@ Download and upload rate limits can only be set for the http adapter (node.js):
|
|
|
1524
1888
|
```js
|
|
1525
1889
|
const { data } = await axios.post(LOCAL_SERVER_URL, myBuffer, {
|
|
1526
1890
|
onUploadProgress: ({ progress, rate }) => {
|
|
1527
|
-
console.log(
|
|
1528
|
-
`Upload [${(progress * 100).toFixed(2)}%]: ${(rate / 1024).toFixed(2)}KB/s`,
|
|
1529
|
-
);
|
|
1891
|
+
console.log(`Upload [${(progress * 100).toFixed(2)}%]: ${(rate / 1024).toFixed(2)}KB/s`);
|
|
1530
1892
|
},
|
|
1531
1893
|
|
|
1532
1894
|
maxRate: [100 * 1024], // 100KB/s limit
|
|
@@ -1561,18 +1923,18 @@ The headers object is always initialized inside interceptors and transformers:
|
|
|
1561
1923
|
|
|
1562
1924
|
```ts
|
|
1563
1925
|
axios.interceptors.request.use((request: InternalAxiosRequestConfig) => {
|
|
1564
|
-
request.headers.set(
|
|
1926
|
+
request.headers.set('My-header', 'value');
|
|
1565
1927
|
|
|
1566
1928
|
request.headers.set({
|
|
1567
|
-
|
|
1568
|
-
|
|
1929
|
+
'My-set-header1': 'my-set-value1',
|
|
1930
|
+
'My-set-header2': 'my-set-value2',
|
|
1569
1931
|
});
|
|
1570
1932
|
|
|
1571
|
-
request.headers.set(
|
|
1933
|
+
request.headers.set('User-Agent', false); // disable subsequent setting the header by Axios
|
|
1572
1934
|
|
|
1573
|
-
request.headers.setContentType(
|
|
1935
|
+
request.headers.setContentType('text/plain');
|
|
1574
1936
|
|
|
1575
|
-
request.headers[
|
|
1937
|
+
request.headers['My-set-header2'] = 'newValue'; // direct access is deprecated
|
|
1576
1938
|
|
|
1577
1939
|
return request;
|
|
1578
1940
|
});
|
|
@@ -1582,9 +1944,9 @@ You can iterate over an `AxiosHeaders` instance using a `for...of` statement:
|
|
|
1582
1944
|
|
|
1583
1945
|
```js
|
|
1584
1946
|
const headers = new AxiosHeaders({
|
|
1585
|
-
foo:
|
|
1586
|
-
bar:
|
|
1587
|
-
baz:
|
|
1947
|
+
foo: '1',
|
|
1948
|
+
bar: '2',
|
|
1949
|
+
baz: '3',
|
|
1588
1950
|
});
|
|
1589
1951
|
|
|
1590
1952
|
for (const [header, value] of headers) {
|
|
@@ -1683,26 +2045,26 @@ matcher function or internal key-value parser.
|
|
|
1683
2045
|
|
|
1684
2046
|
```ts
|
|
1685
2047
|
const headers = new AxiosHeaders({
|
|
1686
|
-
|
|
2048
|
+
'Content-Type': 'multipart/form-data; boundary=Asrf456BGe4h',
|
|
1687
2049
|
});
|
|
1688
2050
|
|
|
1689
|
-
console.log(headers.get(
|
|
2051
|
+
console.log(headers.get('Content-Type'));
|
|
1690
2052
|
// multipart/form-data; boundary=Asrf456BGe4h
|
|
1691
2053
|
|
|
1692
|
-
console.log(headers.get(
|
|
2054
|
+
console.log(headers.get('Content-Type', true)); // parse key-value pairs from a string separated with \s,;= delimiters:
|
|
1693
2055
|
// [Object: null prototype] {
|
|
1694
2056
|
// 'multipart/form-data': undefined,
|
|
1695
2057
|
// boundary: 'Asrf456BGe4h'
|
|
1696
2058
|
// }
|
|
1697
2059
|
|
|
1698
2060
|
console.log(
|
|
1699
|
-
headers.get(
|
|
1700
|
-
return String(value).replace(/a/g,
|
|
1701
|
-
})
|
|
2061
|
+
headers.get('Content-Type', (value, name, headers) => {
|
|
2062
|
+
return String(value).replace(/a/g, 'ZZZ');
|
|
2063
|
+
})
|
|
1702
2064
|
);
|
|
1703
2065
|
// multipZZZrt/form-dZZZtZZZ; boundZZZry=Asrf456BGe4h
|
|
1704
2066
|
|
|
1705
|
-
console.log(headers.get(
|
|
2067
|
+
console.log(headers.get('Content-Type', /boundary=(\w+)/)?.[0]);
|
|
1706
2068
|
// boundary=Asrf456BGe4h
|
|
1707
2069
|
```
|
|
1708
2070
|
|
|
@@ -1735,9 +2097,9 @@ Unlike the `delete` method matcher, this optional matcher will be used to match
|
|
|
1735
2097
|
|
|
1736
2098
|
```ts
|
|
1737
2099
|
const headers = new AxiosHeaders({
|
|
1738
|
-
foo:
|
|
1739
|
-
|
|
1740
|
-
|
|
2100
|
+
foo: '1',
|
|
2101
|
+
'x-foo': '2',
|
|
2102
|
+
'x-bar': '3',
|
|
1741
2103
|
});
|
|
1742
2104
|
|
|
1743
2105
|
console.log(headers.clear(/^x-/)); // true
|
|
@@ -1756,11 +2118,11 @@ Set `format` to true for converting header names to lowercase and capitalizing t
|
|
|
1756
2118
|
|
|
1757
2119
|
```js
|
|
1758
2120
|
const headers = new AxiosHeaders({
|
|
1759
|
-
foo:
|
|
2121
|
+
foo: '1',
|
|
1760
2122
|
});
|
|
1761
2123
|
|
|
1762
|
-
headers.Foo =
|
|
1763
|
-
headers.FOO =
|
|
2124
|
+
headers.Foo = '2';
|
|
2125
|
+
headers.FOO = '3';
|
|
1764
2126
|
|
|
1765
2127
|
console.log(headers.toJSON()); // [Object: null prototype] { foo: '1', Foo: '2', FOO: '3' }
|
|
1766
2128
|
console.log(headers.normalize().toJSON()); // [Object: null prototype] { foo: '3' }
|
|
@@ -1827,7 +2189,7 @@ To use it by default, it must be selected explicitly:
|
|
|
1827
2189
|
|
|
1828
2190
|
```js
|
|
1829
2191
|
const { data } = axios.get(url, {
|
|
1830
|
-
adapter:
|
|
2192
|
+
adapter: 'fetch', // by default ['xhr', 'http', 'fetch']
|
|
1831
2193
|
});
|
|
1832
2194
|
```
|
|
1833
2195
|
|
|
@@ -1835,7 +2197,7 @@ You can create a separate instance for this:
|
|
|
1835
2197
|
|
|
1836
2198
|
```js
|
|
1837
2199
|
const fetchAxios = axios.create({
|
|
1838
|
-
adapter:
|
|
2200
|
+
adapter: 'fetch',
|
|
1839
2201
|
});
|
|
1840
2202
|
|
|
1841
2203
|
const { data } = fetchAxios.get(url);
|
|
@@ -1859,12 +2221,12 @@ you must disable their use inside the fetch adapter by passing null.
|
|
|
1859
2221
|
Basic example:
|
|
1860
2222
|
|
|
1861
2223
|
```js
|
|
1862
|
-
import customFetchFunction from
|
|
2224
|
+
import customFetchFunction from 'customFetchModule';
|
|
1863
2225
|
|
|
1864
2226
|
const instance = axios.create({
|
|
1865
|
-
adapter:
|
|
2227
|
+
adapter: 'fetch',
|
|
1866
2228
|
onDownloadProgress(e) {
|
|
1867
|
-
console.log(
|
|
2229
|
+
console.log('downloadProgress', e);
|
|
1868
2230
|
},
|
|
1869
2231
|
env: {
|
|
1870
2232
|
fetch: customFetchFunction,
|
|
@@ -1879,20 +2241,20 @@ const instance = axios.create({
|
|
|
1879
2241
|
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.
|
|
1880
2242
|
|
|
1881
2243
|
```js
|
|
1882
|
-
import { fetch } from
|
|
1883
|
-
import axios from
|
|
2244
|
+
import { fetch } from '@tauri-apps/plugin-http';
|
|
2245
|
+
import axios from 'axios';
|
|
1884
2246
|
|
|
1885
2247
|
const instance = axios.create({
|
|
1886
|
-
adapter:
|
|
2248
|
+
adapter: 'fetch',
|
|
1887
2249
|
onDownloadProgress(e) {
|
|
1888
|
-
console.log(
|
|
2250
|
+
console.log('downloadProgress', e);
|
|
1889
2251
|
},
|
|
1890
2252
|
env: {
|
|
1891
2253
|
fetch,
|
|
1892
2254
|
},
|
|
1893
2255
|
});
|
|
1894
2256
|
|
|
1895
|
-
const { data } = await instance.get(
|
|
2257
|
+
const { data } = await instance.get('https://google.com');
|
|
1896
2258
|
```
|
|
1897
2259
|
|
|
1898
2260
|
#### 🔥 Using with SvelteKit
|
|
@@ -1902,17 +2264,14 @@ which makes it incompatible with the standard URL API. So, Axios must be configu
|
|
|
1902
2264
|
|
|
1903
2265
|
```js
|
|
1904
2266
|
export async function load({ fetch }) {
|
|
1905
|
-
const { data: post } = await axios.get(
|
|
1906
|
-
|
|
1907
|
-
{
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
Request: null,
|
|
1912
|
-
Response: null,
|
|
1913
|
-
},
|
|
2267
|
+
const { data: post } = await axios.get('https://jsonplaceholder.typicode.com/posts/1', {
|
|
2268
|
+
adapter: 'fetch',
|
|
2269
|
+
env: {
|
|
2270
|
+
fetch,
|
|
2271
|
+
Request: null,
|
|
2272
|
+
Response: null,
|
|
1914
2273
|
},
|
|
1915
|
-
);
|
|
2274
|
+
});
|
|
1916
2275
|
|
|
1917
2276
|
return { post };
|
|
1918
2277
|
}
|
|
@@ -1931,21 +2290,17 @@ Note: HTTP/2 redirects are currently not supported by the HTTP/2 adapter.
|
|
|
1931
2290
|
```js
|
|
1932
2291
|
const form = new FormData();
|
|
1933
2292
|
|
|
1934
|
-
form.append(
|
|
2293
|
+
form.append('foo', '123');
|
|
1935
2294
|
|
|
1936
|
-
const { data, headers, status } = await axios.post(
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
},
|
|
1946
|
-
responseType: "arraybuffer",
|
|
1947
|
-
}
|
|
1948
|
-
);
|
|
2295
|
+
const { data, headers, status } = await axios.post('https://httpbin.org/post', form, {
|
|
2296
|
+
onUploadProgress(e) {
|
|
2297
|
+
console.log('upload progress', e);
|
|
2298
|
+
},
|
|
2299
|
+
onDownloadProgress(e) {
|
|
2300
|
+
console.log('download progress', e);
|
|
2301
|
+
},
|
|
2302
|
+
responseType: 'arraybuffer',
|
|
2303
|
+
});
|
|
1949
2304
|
```
|
|
1950
2305
|
|
|
1951
2306
|
## Semver
|
|
@@ -1964,7 +2319,7 @@ axios includes [TypeScript](https://typescriptlang.org) definitions and a type g
|
|
|
1964
2319
|
```typescript
|
|
1965
2320
|
let user: User = null;
|
|
1966
2321
|
try {
|
|
1967
|
-
const { data } = await axios.get(
|
|
2322
|
+
const { data } = await axios.get('/user?ID=12345');
|
|
1968
2323
|
user = data.userDetails;
|
|
1969
2324
|
} catch (error) {
|
|
1970
2325
|
if (axios.isAxiosError(error)) {
|
|
@@ -1984,10 +2339,10 @@ If you use TypeScript to type check CJS JavaScript code, your only option is to
|
|
|
1984
2339
|
You can also create a custom instance with typed interceptors:
|
|
1985
2340
|
|
|
1986
2341
|
```typescript
|
|
1987
|
-
import axios, { AxiosInstance, InternalAxiosRequestConfig } from
|
|
2342
|
+
import axios, { AxiosInstance, InternalAxiosRequestConfig } from 'axios';
|
|
1988
2343
|
|
|
1989
2344
|
const apiClient: AxiosInstance = axios.create({
|
|
1990
|
-
baseURL:
|
|
2345
|
+
baseURL: 'https://api.example.com',
|
|
1991
2346
|
timeout: 10000,
|
|
1992
2347
|
});
|
|
1993
2348
|
|
|
@@ -2003,6 +2358,23 @@ You can use Gitpod, an online IDE(which is free for Open Source) for contributin
|
|
|
2003
2358
|
|
|
2004
2359
|
[](https://gitpod.io/#https://github.com/axios/axios/blob/main/examples/server.js)
|
|
2005
2360
|
|
|
2361
|
+
## Contributing
|
|
2362
|
+
|
|
2363
|
+
### Local setup
|
|
2364
|
+
|
|
2365
|
+
As a supply-chain hardening measure, this repository ships a project-level `.npmrc` that sets `ignore-scripts=true`. This blocks npm lifecycle scripts (`preinstall`, `install`, `postinstall`, `prepare`) from any direct or transitive dependency when you run `npm install` or `npm ci` inside the repo. See [THREATMODEL.md](./THREATMODEL.md) (threat T-S2) for the rationale.
|
|
2366
|
+
|
|
2367
|
+
One consequence: the repository's own `prepare` hook (which installs Husky's git hooks) will **not** run automatically. After your first install, enable the git hooks manually:
|
|
2368
|
+
|
|
2369
|
+
```bash
|
|
2370
|
+
npm ci
|
|
2371
|
+
npm rebuild husky && npx husky
|
|
2372
|
+
```
|
|
2373
|
+
|
|
2374
|
+
Run those two commands once per fresh checkout. You do **not** need to re-run them after every subsequent `npm install`.
|
|
2375
|
+
|
|
2376
|
+
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.
|
|
2377
|
+
|
|
2006
2378
|
## Resources
|
|
2007
2379
|
|
|
2008
2380
|
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
|