axios-cancelable
v1.0.0
Published
Utility for cancellation of requests when using axios
Downloads
188
Readme
axios-cancelable
Utility for cancellation of requests when using axios
Table of Contents
About
Personalized and actively maintained fork of axios-cancel
Install
This project uses node and npm.
$ npm install axios-cancelable
$ # OR
$ yarn add axios-cancelable
Usage
import axios from 'axios';
import axiosCancel from 'axios-cancelable';
axiosCancel(axios, {
debug: false // default
});
...
// Single request cancellation
const requestId = 'my_sample_request';
const promise = axios.get(url, {
requestId: requestId
})
.then((res) => {
console.log('resolved');
}).catch((thrown) => {
if (axios.isCancel(thrown)) {
console.log('request cancelled');
} else {
console.log('some other reason');
}
});
axios.cancel(requestId);
// aborts the HTTP request and logs `request cancelled`
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT