35
35
- [ Features] ( #features )
36
36
- [ Browser Support] ( #browser-support )
37
37
- [ Installing] ( #installing )
38
+ - [ Package manager] ( #package-manager )
39
+ - [ CDN] ( #cdn )
38
40
- [ Example] ( #example )
39
41
- [ Axios API] ( #axios-api )
40
42
- [ Request method aliases] ( #request-method-aliases )
@@ -93,6 +95,8 @@ Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
93
95
94
96
## Installing
95
97
98
+ ### Package manager
99
+
96
100
Using npm:
97
101
98
102
``` bash
@@ -117,7 +121,39 @@ Using pnpm:
117
121
$ pnpm add axios
118
122
```
119
123
120
- Using jsDelivr CDN:
124
+ Once the package is installed, you can import the library using ` import ` or ` require ` approach:
125
+
126
+ ``` js
127
+ import axios , {isCancel , AxiosError } from ' axios' ;
128
+ ```
129
+
130
+ You can also use the default export, since the named export is just a re-export from the Axios factory:
131
+
132
+ ``` js
133
+ import axios from ' axios' ;
134
+
135
+ console .log (axios .isCancel (' something' ));
136
+ ````
137
+
138
+ If you use ` require` for importing, ** only default export is available ** :
139
+
140
+ ` ` ` js
141
+ const axios = require('axios');
142
+
143
+ console.log(axios.isCancel('something'));
144
+ ` ` `
145
+
146
+ For cases where something went wrong when trying to import a module into a custom or legacy environment,
147
+ you can try importing the module package directly:
148
+
149
+ ` ` ` js
150
+ const axios = require('axios/dist/browser/axios.cjs'); // browser commonJS bundle (ES2017)
151
+ // const axios = require('axios/dist/node/axios.cjs'); // node commonJS bundle (ES2017)
152
+ ` ` `
153
+
154
+ ### CDN
155
+
156
+ Using jsDelivr CDN (ES5 UMD browser module ):
121
157
122
158
` ` ` html
123
159
<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
@@ -131,19 +167,11 @@ Using unpkg CDN:
131
167
132
168
## Example
133
169
134
- ### note: CommonJS usage
135
- In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with ` require() ` use the following approach:
136
-
137
- ``` js
138
- const axios = require (' axios' ).default ;
139
-
140
- // axios.<method> will now provide autocomplete and parameter typings
141
- ```
142
-
143
170
Performing a ` GET` request
144
171
145
172
` ` ` js
146
- const axios = require (' axios' ).default ;
173
+ import axios from 'axios';
174
+ //const axios = require('axios'); // legacy way
147
175
148
176
// Make a request for a user with a given ID
149
177
axios.get('/user?ID=12345')
0 commit comments