mirror of
https://github.com/tenrok/axios.git
synced 2026-05-21 13:24:11 +03:00
Updating docs
This commit is contained in:
@@ -305,7 +305,12 @@ These are the available config options for making requests. Only the `url` is re
|
||||
proxy: {
|
||||
host: '127.0.0.1',
|
||||
port: 9000
|
||||
}
|
||||
},
|
||||
|
||||
// `cancelToken` specifies a cancel token that can be used to cancel the request
|
||||
// (see Cancellation section below for details)
|
||||
cancelToken: new CancelToken(function (cancel) {
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
@@ -457,6 +462,51 @@ axios.get('/user/12345', {
|
||||
})
|
||||
```
|
||||
|
||||
## Cancellation
|
||||
|
||||
You can cancel a request using a *cancel token*.
|
||||
|
||||
> The axios cancel token API is based on [cancelable promises proposal](https://github.com/tc39/proposal-cancelable-promises), which is currently at Stage 1.
|
||||
|
||||
You can create a cancel token by passing an executor function to the `CancelToken` constructor as shown below:
|
||||
|
||||
```js
|
||||
var Cancel = axios.Cancel;
|
||||
var CancelToken = axios.CancelToken;
|
||||
|
||||
var cancel;
|
||||
|
||||
axios.get('/user/12345', {
|
||||
cancelToken: new CancelToken(function executor(c) {
|
||||
// An executor function receives a cancel function as a parameter
|
||||
// You can use the cancel function to cancel the request later
|
||||
cancel = c;
|
||||
})
|
||||
}).catch(function(thrown) {
|
||||
if (thrown instanceof Cancel) {
|
||||
console.log('Request canceled', thrown.message);
|
||||
} else {
|
||||
// handle error
|
||||
}
|
||||
});
|
||||
|
||||
// cancel the request (the message parameter is optional)
|
||||
cancel('Operation canceled by the user.');
|
||||
```
|
||||
|
||||
You can also create a cancel token using the `CancelToken.source` factory:
|
||||
|
||||
```js
|
||||
var CancelToken = axios.CancelToken;
|
||||
var source = CancelToken.source();
|
||||
|
||||
axios.get('/user/12345', {
|
||||
cancelToken: source.token
|
||||
});
|
||||
|
||||
source.cancel();
|
||||
```
|
||||
|
||||
## Semver
|
||||
|
||||
Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes.
|
||||
|
||||
Reference in New Issue
Block a user