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); +};