From 38be3b2e18fd35bc89d46a6cd3fe2379191fd5f6 Mon Sep 17 00:00:00 2001 From: Akash Dhar Dubey Date: Tue, 30 Dec 2025 16:39:44 +0530 Subject: [PATCH] docs: add abort controller example (#7287) Co-authored-by: Jay --- examples/abort-controller/index.html | 132 +++++++++++++++++++++++++++ examples/abort-controller/server.js | 16 ++++ 2 files changed, 148 insertions(+) create mode 100644 examples/abort-controller/index.html create mode 100644 examples/abort-controller/server.js diff --git a/examples/abort-controller/index.html b/examples/abort-controller/index.html new file mode 100644 index 0000000..bd3747a --- /dev/null +++ b/examples/abort-controller/index.html @@ -0,0 +1,132 @@ + + + + axios - abort controller example + + + + +

axios.AbortController

+ +
+
+

1. Single Request Cancellation

+

Click "Start Request" to begin a 3-second request. Click "Cancel Request" to abort it.

+ + +
+
+
+ +
+ +
+
+

2. Search-as-you-type (Race Condition Handling)

+

Type quickly. Previous pending requests will be cancelled automatically.

+
+ +
+
+
    +
    +
    + + + + + diff --git a/examples/abort-controller/server.js b/examples/abort-controller/server.js new file mode 100644 index 0000000..8e27326 --- /dev/null +++ b/examples/abort-controller/server.js @@ -0,0 +1,16 @@ +import url from 'url'; + +export default function (req, res) { + const parsedUrl = url.parse(req.url, true); + const delay = parsedUrl.query.delay || 3000; + + setTimeout(() => { + res.writeHead(200, { + 'Content-Type': 'text/json' + }); + res.write(JSON.stringify({ + message: 'Response completed successfully after ' + delay + 'ms' + })); + res.end(); + }, delay); +};