Registry / networking / axios-cancel

axios-cancel

JSON →
library0.2.2jsnpmunverified

A lightweight library (v0.2.2, last release Nov 2017, no active development) that simplifies cancelling Axios HTTP requests by providing a thin wrapper around Axios's built-in cancellation API. It allows assigning a requestId per request and cancelling individual requests via axios.cancel(id) or all pending requests via axios.cancelAll(). Unlike using raw CancelToken, axios-cancel manages cancellation tokens internally, reducing boilerplate. Works with Axios >=0.15.0. Current version is stable but unmaintained; consider using Axios's native cancellation with AbortController for newer Axios versions.

npm install axios-cancel
INSTALL
IMPORT
SIG · AXIOS-CANCEL
A
axios-cancel
networkingjavascriptv0.2.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (axiosCancel)
import axiosCancel from 'axios-cancel'
const axiosCancel = require('axios-cancel')
Library exports a default function; CommonJS require works but may be polyfilled.
axios.cancel()
axios.cancel(requestId, reason?)
axios.Cancel(requestId)
Method added to axios instance after calling axiosCancel(). Must use lowercase 'cancel'.
axios.cancelAll()
axios.cancelAll(reason?)
axios.cancelAll() with no argument but expecting reason object
Cancels all pending requests. Optional reason string.

Initialize axios-cancel, make a GET request with a requestId, and cancel it programmatically.

import axios from 'axios'; import axiosCancel from 'axios-cancel'; // Initialize (must be called once) axiosCancel(axios, { debug: false }); const requestId = 'my_request'; axios.get('https://jsonplaceholder.typicode.com/posts', { requestId }) .then(res => console.log('Success:', res)) .catch(thrown => { if (axios.isCancel(thrown)) { console.log('Request cancelled:', thrown.message); } else { console.error('Error:', thrown); } }); // Cancel the request after 100ms setTimeout(() => { axios.cancel(requestId, 'User aborted'); }, 100);
Debug
Known issues
deprecatedaxios-cancel is no longer maintained; use native AbortController or Axios built-in cancellation.
fix
Migrate to AbortController or use Axios cancel token directly.
affects: >=0.1.0
gotchaCalling axiosCancel() modifies the global axios instance; avoid using multiple instances.
fix
Pass a specific axios instance, e.g., const instance = axios.create(); axiosCancel(instance);
affects: >=0.1.0
breakingRequest cancellation with same requestId cancels previous request but may cause race conditions.
fix
Ensure unique requestIds or handle cancellation in catch() properly.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: axios.cancel is not a function
axiosCancel() was not called before using axios.cancel().
fix
Call axiosCancel(axios) at app initialization.
Error: requestId is required
Missing requestId in request config when using cancellation.
fix
Add requestId to the request config object.
Uncaught (in promise) Cancel: canceled
When a request is cancelled, the promise rejects with a Cancel object.
fix
Use axios.isCancel() to differentiate cancellation from other errors.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies
axiosrequiredPeer dependency; modifies Axios prototype to add cancel methods
Agent activity
29 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
axios-cancel — npm install axios-cancel · libregistry