const cancelTokenSource = axios.CancelToken.source();
axios.get('/user/12345', {
cancelToken: cancelTokenSource.token
});
// Cancel request
cancelTokenSource.cancel();
//Starting from v0.22.0 Axios supports AbortController to cancel requests in fetch API way:
const controller = new AbortController();
axios.get('/foo/bar', {
signal: controller.signal
}).then(function(response) {
//...
});
// cancel the request
controller.abort()
const controller = new AbortController();
axios.get('/foo/bar', {
signal: controller.signal
}).then(function(response) {
//...
});
// cancel the request
controller.abort()
import axios from "axios";
/// DELETE REQUEST
handleDeleteById(id).then((res) => {
alert("deleted")
});
function handleDeleteById(id) {
// console.log(data);
// {name: "mysore", population: 11111, country: "India"}
return axios({
baseURL: "baseURL",
url: `/${id}`,
method: "DELETE"
});
}
axios.delete(url, { data: { foo: "bar" }, headers: { "Authorization": "***" } });
import axios from 'axios'
const query = useQuery(['todos'], ({ signal }) =>
axios.get('/todos', {
// Pass the signal to `axios`
signal,
})
)