question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC] API for canceling HTTP requests

See original GitHub issue

Overview

I would like to revive the discussion about canceling HTTP requests (#50) as there is clearly a demand for this feature. I suggest considering the following options. /cc @mzabriskie

Option 1

API

var axios = require('axios');

function generateRequestId() {
  // Return a unique request ID
}

var requestId = generateRequestId(); 
axios.get('/user', { requestId: requestId });
axios.abort(requestId);

Implementation

PR #330

Option 2

API

var axios = require('axios');
var Cancellation = axios.Cancellation;

var cancellation = new Cancellation();
axios.get('/user', { cancellation: cancellation });
cancellation.cancel();

Notes

  • When a request is canceled, the Promise is rejected with a CancellationError. This allows the caller to distinguish between a cancellation and a failure.
  • The same Cancellation object can be used to cancel multiple different requests.

Implementation

I created a separate library that can be used as a base for implementing request cancellation in axios: https://github.com/nickuraltsev/cancel. (The example on the README.md shows how to implement a simple HTTP client that supports cancellation.) We can copy all the code from this library to axios or add this library as a dependency.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:14
  • Comments:24 (10 by maintainers)

github_iconTop GitHub Comments

25reactions
nickuraltsevcommented, Aug 17, 2016

Great, I’ll submit a PR soon.

15reactions
nickuraltsevcommented, Sep 18, 2016

I’ve just submitted a PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the Correct HTTP Status Code for a Cancelled Request
HTTP (1.0/1.1) doesn't have a means to cancel a request. All that a client can do if it no longer ... Quoting from...
Read more >
RFC 7233 - Hypertext Transfer Protocol (HTTP/1.1)
Introduction Hypertext Transfer Protocol (HTTP) clients often encounter interrupted data transfers as a result of canceled requests or dropped connections.
Read more >
RFC 7230: Hypertext Transfer Protocol (HTTP/1.1)
RFC 7230 HTTP/1.1 Message Syntax and Routing June 2014 3.2.1. ... request message, usually due to a canceled request or a triggered timeout...
Read more >
Cancel HTTP Requests Last Updated June 6, 2022 - TechDocs
/** * API to cancel a pending HTTP request that was invoked using the API invoke:taksBlock:completion: * This is a best effort cancel...
Read more >
CreateRfc - AWS Managed Services - AWS Documentation
Creates a new RFC. To create a request for change, begin by calling CreateRfc. After creating the basic RFC and before submitting it,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found