Request Cancellation with AbortController in JavaScript

From the Axios cheat sheet · Request Cancellation & Timeout · verified Jul 2026

Request Cancellation with AbortController

Cancel in-flight requests using modern AbortController API

javascript
// Cancel a request
const controller = new AbortController();

axios.get('/api/users', {
  signal: controller.signal
}).catch(error => {
  if (axios.isCancel(error)) {
    console.log('Request cancelled:', error.message);
  }
});

// Cancel the request
controller.abort();
✅ AbortController is the modern standard for request cancellation
💡 Essential for search inputs to cancel outdated requests
🔍 Always cleanup controllers in useEffect/componentWillUnmount
⚡ Prevents race conditions when user types quickly in search
cancelabortabortcontrollercleanup

More JavaScript tasks

Back to the full Axios cheat sheet