How to cancel a fetch request

Posted by Jessica Taylor | Updated on

Until a few days back, One shortcoming of native promises is no direct way to cancel a fetch request. But the new AbortController from js specification allows you to use a signal to abort one or multiple fetch calls. The basic flow of cancelling a fetch request would be as below,

  1. Create an AbortController instance
  2. Get the signal property of an instance and pass the signal as a fetch option for signal
  3. Call the AbortController’s abort property to cancel all fetches that use that signal For example, let’s pass the same signal to multiple fetch calls will cancel all requests with that signal,

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers