# axios
[![npm version](https://img.shields.io/npm/v/axios.svg?style=flat-square)](https://www.npmjs.org/package/axios)
[![build status](https://img.shields.io/travis/axios/axios/master.svg?style=flat-square)](https://travis-ci.org/axios/axios)
[![code coverage](https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square)](https://coveralls.io/r/mzabriskie/axios)
[![install size](https://packagephobia.now.sh/badge?p=axios)](https://packagephobia.now.sh/result?p=axios)
[![npm downloads](https://img.shields.io/npm/dm/axios.svg?style=flat-square)](http://npm-stat.com/charts.html?package=axios)
[![gitter chat](https://img.shields.io/gitter/room/mzabriskie/axios.svg?style=flat-square)](https://gitter.im/mzabriskie/axios)
[![code helpers](https://www.codetriage.com/axios/axios/badges/users.svg)](https://www.codetriage.com/axios/axios)
Promise based HTTP client for the browser and node.js
## Features
- Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser
- Make [http](http://nodejs.org/api/http.html) requests from node.js
- Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
- Intercept request and response
- Transform request and response data
- Cancel requests
- Automatic transforms for JSON data
- Client side support for protecting against [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
## Browser Support
![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |
--- | --- | --- | --- | --- | --- |
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
[![Browser Matrix](https://saucelabs.com/open_sauce/build_matrix/axios.svg)](https://saucelabs.com/u/axios)
## Installing
Using npm:
```bash
$ npm install axios
```
Using bower:
```bash
$ bower install axios
```
Using yarn:
```bash
$ yarn add axios
```
Using cdn:
```html
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
```
## Example
### note: CommonJS usage
In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with `require()` use the following approach:
```js
const axios = require('axios').default;
// axios.<method> will now provide autocomplete and parameter typings
```
Performing a `GET` request
```js
const axios = require('axios');
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
// Optionally the request above could also be done as
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
// always executed
});
// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}
```
> **NOTE:** `async/await` is part of ECMAScript 2017 and is not supported in Internet
> Explorer and older browsers, so use with caution.
Performing a `POST` request
```js
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
```
Performing multiple concurrent requests
```js
function getUserAccount() {
return axios.get('/user/12345');
}
function getUserPermissions() {
return axios.get('/user/12345/permissions');
}
axios.all([getUserAccount(), getUserPermissions()])
.then(axios.spread(function (acct, perms) {
// Both requests are now complete
}));
```
## axios API
Requests can be made by passing the relevant config to `axios`.
##### axios(config)
```js
// Send a POST request
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
});
```
```js
// GET request for remote image
axios({
method: 'get',
url: 'http://bit.ly/2mTM3nY',
responseType: 'stream'
})
.then(function (response) {
response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
});
```
##### axios(url[, config])
```js
// Send a GET request (default method)
axios('/user/12345');
```
### Request method aliases
For convenience aliases have been provided for all supported request methods.
##### axios.request(config)
##### axios.get(url[, config])
##### axios.delete(url[, config])
##### axios.head(url[, config])
##### axios.options(url[, config])
##### axios.post(url[, data[, config]])
##### axios.put(url[, data[, config]])
##### axios.patch(url[, data[, config]])
###### NOTE
When using the alias methods `url`, `method`, and `data` properties don't need to be specified in config.
### Concurrency
Helper functions for dealing with concurrent requests.
##### axios.all(iterable)
##### axios.spread(callback)
### Creating an instance
You can create a new instance of axios with a custom config.
##### axios.create([config])
```js
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});
```
### Instance methods
The available instance methods are listed below. The specified config will be merged with the instance config.
##### axios#request(config)
##### axios#get(url[, config])
##### axios#delete(url[, config])
##### axios#head(url[, config])
##### axios#options(url[, config])
##### axios#post(url[, data[, config]])
##### axios#put(url[, data[, config]])
##### axios#patch(url[, data[, config]])
##### axios#getUri([config])
## Request Config
These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified.
```js
{
// `url` is the server URL that will be used for the request
url: '/user',
// `method` is the request method to be used when making the request
method: 'get', // default
// `baseURL` will be prepended to `url` unless `url` is absolute.
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
// to methods of that instance.
baseURL: 'https://some-domain.com/api/',
// `transformRequest` allows changes to the request data before it is sent to the server
// This is only applicable for request methods 'PUT', 'POST', 'PATCH' and 'DELETE'
// The last function in the array must return a string or an instance of Buffer, ArrayBuffer,
// FormData or Stream
// You may modify the headers object.
transformRequest: [function (data, headers) {
// Do whatever you want to transform the data
return data;
}],
// `transformResponse` allows changes to the response data to be made before
// it is passed to then/catch
transformResponse: [function (data) {
// Do whatever you want to transform the data
return data;
}],
// `headers` are custom headers to be sent
headers: {'X-Requested-With': 'XMLHttpRequest'},
// `params` are the URL parameters to be sent with the request
// Must be a plain object or a URLSearchParams object
params: {
ID: 12345
},
// `paramsSerializer` is an optional function in charge of serializing `params`
// (e.g. https://w
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ajax-promise-axios代码.zip (306个子文件)
02e761cb306f210377f6255167f7f79911de3b 902B
0511ee9a1f33d6c3383fe44e33b0ee0e7d93a8 742B
08ecc29cc795c823352d8367a977ee5dab7354 400B
09254d1604701cd1b79f07c9eeb9df2f8a069b 8KB
094c597e75a1cbf7fd7b2dfde44a40c369b9f0 2KB
0a9b5e2225489a8636bd6532c6405ca936bba0 254B
0ae4f4305c02a639acb4b65c8383442d407d35 52B
0b2db8f72bff20e905dfa23b0df998f37b0ae5 635B
0d21e3322b9d2778786ea743dd5e818991d595 5KB
0d98d0ab329343628918636143289b883a083e 877B
0dcbab0823de7ff7e81c99337567dfc782642c 61B
1184958c0afb24218672bf84237a9407e4c648 1KB
13a1164e38b66ca38d7b8eed716c852e217bcf 857B
13daf41d0cd0b15d3a9705e543f741f3f4bdfb 1KB
149ff5296aa11442834d29fdc8565bb159d0be 2KB
150de4053362cd4a47179d030e694319e8f0c3 565B
15dc8cb0fd35e120b8f27039dac913d200be11 2KB
16531a7f24ad84d894c903fde50492f0d9ba35 792B
18821c2749b2165cae14126adf5d524e0b65f6 435B
19126c85b35b76cb9f6a1811e295a72e7b2865 413B
1914945c4889a70adf00a114130c986b047baa 1KB
1a85c783879e888f4cf62e0615bd4b68a3b728 1015B
1acde3fc5eee4aa453117f2a0364546fe23ef8 905B
1c921d99a7371e8cdeaeee43579f6bc3da77f6 54B
1c9ac886da5f9c45e0a03ed038cbb938e0bc8d 1KB
1c9d3134fb95bf995f86cf6b62de13d74490a2 373B
1d2ef38c0720d76583c23aa00fa4c3ae6740c8 1KB
1e8b7de418306d310e6bb40ab92f120c923b63 82B
1f0912ddf106423075e183f8914a60084fedf3 425B
1fd186af4130f0584e3750cacdcbe9ee266a01 1KB
24e09a4114787231f9151ce45445db7d1f2cf1 296B
29758943979f0b37f54ff96cb533afb7d94754 799B
2a8a6e2e1896e7a9da1b7c84c45d0d2f1c8ef5 694B
2af509a5d9176c85b2ab80aa1963cec346075d 114B
2b863cbda1b23f21e149c4f1583ca574297739 54B
2c52c1299fabca2756ae079ae09dbd2d650a92 1KB
2cbada545ef218c598a58dabd7014e1701cb60 704B
2f53f30ab59e9e03d4793b02fa03f6c607745a 143B
2fcb91068e6728ec79b4067f0eac66069cf7c1 805B
30a1967f9dec8e7b26052942becb44acced95c 166B
340e019b4a2bdf946104a8da7499c01ed51204 547B
3758a725ac0078e893778dfd8d186b9f55e339 730B
3818396025b010c9cb9ddc44e2189ca2db8c45 1KB
3a133a9afb6a9c2b935fce274b9ea49b2aaee2 424B
3a82d15bd72b3cdf9ba4108272985f7e0bfdb3 808B
3ac54a5bb725d6418536d7de991d5765df8b93 106B
3ac5b7340fa8a3471b5e573d7ea16a5855daf7 3KB
3bc4861130c87687c8fca4045b86c585ce36b7 225B
3d6f213da7679e94c4e55231099e25e780beae 785B
407ab7a59721b4c401e743ec72b0e9392ff9d8 941B
40d69694091db47a7eddb66e947f6700297a17 145B
41337903c39da8e3998ae36dd7cac6e1358bfa 3KB
424a0e30cedeea6823084e774a822e5160d384 1KB
42d08e84b9a7033961dec960e53896ec432c0c 2KB
4550a1e0180b286b74da5389156273e955ccb7 588B
46df504f976114ac8ec36f6ff335a09987adbb 302B
47a656bb1f3804630c2187fccd72aedd90ec80 400B
486bacceab01916bc97cd68a7f4850b4b29531 898B
4a0f071f2b73ddfa2c02aef6dcd83250152f76 3KB
4bd973550a79ae186c44d33a1125387f3a2fcc 1KB
4c171b7af4566c4fda03d073be8b03ca50e816 496B
4ef23bd03e29627b4590b9ab554d05919a3467 837B
522b16b3a3bf5e93aa5b8bf485f866ff71c5c2 1KB
56639742cca5f57b5268f5de2bc62140df1398 208B
58be540d3e657403a2a64acf573acc20ccd164 351B
5b8f6627ff5e16cec69a99043b7c9d09c8a880 860B
5e356174a86759d476ae3c4098206580076fbd 53B
5eb7c1d22899671446c57a1340b14e6271d494 166B
60eecc84e219e52554407ad38d04abd1cf2111 78B
61b6092756f9d60a7a1f52f31071f24ea6ed6a 269B
61d3ae2d07c59ce10fca8974c3ea00f8e5a404 1KB
6371edbe325121c7666716c0fe238310b5e6ca 150B
64300377fa424ed6b2651e72aaa3d68cd2075f 144B
66fb9c00919bf71317101ebe1096df0e43b215 2KB
67e6cee1f171951817872fbeb01d98c9dd5918 54B
68e8ca31351cb61112cef6d996ef0b59dc8567 228B
69dc3078d4d266043b5c51a0ca165384fda83f 505B
6b2dfa290a6f82bcd67c7a279e1ccee96dc50d 313B
6c80ef27bf3e7bcb57ce60167ec4b5646a223a 653B
6cecbaf6f9af3f063545bb99333914ac183a15 522B
6e903d924f7c9d504a29e8f5c98bc83dbac709 510B
6f74cd56768e3a15ba7b129ee50de6929197cb 789B
7012907221b7eb4e6e9eedd6eb081718ba36a5 15KB
705a4ff737159367a42a6e0a1fb56fb56b8fbc 106B
70a24abef8b149cb5a06933f48763407690022 946B
7297a3aa56b75681bb01eb02e04fcd37fb4ccb 4KB
72ccabb29248288d48f6dde634fdd3f0e2e5f8 2KB
7356d8df3c853788eee7d90528ba94a6f49c16 533B
754d17b164ad9c15b82e26426afa71298a34d1 6KB
765b7062aecb65ab0a1be28a0f61966b323ea6 1KB
76714bebdb5d63751a7920afd26c78c84031f1 1KB
782af41ec3f10462ccfc4e741de2519f157056 193B
7acb6de76033cd3b82911940e7ea677e788baf 112B
7b7ff2b588ea215b2152c4c91c0e978d5cd25a 877B
7c0e3863645a873d0ec6922d09eab2ebedcf65 5KB
7cf0eb45fee16f04395a6ebaf5b7430abae372 269B
7eb0d2c46bf4820c4dcdba3238baae98424e3e 1KB
86cf4f03cdc423f032c60a324c69be776ed829 302B
8c933d28255e8c716899789e8c0f846e5dc125 682B
92b1ed73e051af9daa9086514aa90bf6dc68fe 286B
共 306 条
- 1
- 2
- 3
- 4
资源评论
开测开测
- 粉丝: 1041
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功