Skip to content
pubscout

cancellation_token_http

2.1.0, released 2 years ago by jonathancole.dev

A fork of Dart's HTTP package with request cancellation support using cancellation tokens.

$ flutter pub add cancellation_token_http
Source repository

What it does

It wraps Dart's official HTTP package to allow ongoing network requests to be cancelled via a CancellationProvider/CancellationToken. It also supports canceling isolate-based JSON parsing when paired with the cancellation_token package.

AI-written summary of version 2.1.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to cancel pending HTTP requests in a Dart or Flutter application.
  • You want a drop-in fork of the standard http package with cancellation capabilities.

Skip it when

  • You are already using Dio or another networking package that natively supports request cancellation.
  • You do not need request cancellation functionality.

Strengths

  • Maintains the familiar API of Dart's official http package.
  • Integrates seamlessly with the cancellation_token package for combined network and isolate parsing cancellation.

Weaknesses

  • It is a fork of the standard http package, meaning updates from upstream must be manually merged by the maintainer.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
5
import 'package:cancellation_token_http/http.dart' as http;

var token = http.CancellationToken();
try {
  var response = await http.get(
    Uri.parse('https://example.com/foobar.txt'),
    cancellationToken: token,
  );
} on http.CancelledException {
  print('Request cancelled');
}

Alternatives

Packages that do the same job and could replace cancellation_token_http.

  • http

    Pick the official http package if you do not require request cancellation features.

  • dio

    Pick dio for a full-featured HTTP client that includes built-in request cancellation, interceptors, and global configuration.

Works with

Packages commonly used together with cancellation_token_http: ones it builds on, ones built on it, and its own family.