Aborting Requests with AbortController
Cancel in-flight requests cleanly.
Why Cancel a Request
Sometimes you start a request you no longer need: the user navigates away, types a new search, or a timeout elapses. AbortController lets you cancel an in-flight fetch.
Creating a Controller
Make an AbortController. It exposes a signal you pass to fetch and an abort() method to cancel.
const controller = new AbortController();
console.log(controller.signal); // an AbortSignalAll lessons in this course
- Making GET Requests
- POST and Sending Data
- Handling Errors and Status Codes
- Aborting Requests with AbortController