http_client 1.0.3

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 90

Platform-independent HTTP client #

A platform-independent HTTP client API supporting browser, console, and curl (for SOCKS proxy). Planned platforms: Fetch API, node_io.

Usage: #

To develop your platform-agnostic library, use only the base import:

import 'package:http_client/http_client.dart' as http;

class MyServiceClient {
  final http.Client httpClient;
  MyServiceClient(this.httpClient);
}

For console apps:

import 'package:http_client/console.dart' as http;

main() async {
  http.Client client = new http.ConsoleClient();
  // use the client, eg.:
  // new MyServiceClient(client)
  await client.close();
}

For browser use, only change the first import:

import 'package:http_client/browser.dart' as http;

main() {
  http.Client client = new http.BrowserClient();
  // use the client, eg.:
  // new MyServiceClient(client)
  await client.close();
}

Changelog #

1.0.3 #

  • CloseClientFn in UpdatingClient.

1.0.2 #

  • Class-level invalidateOnError and forceCloseOnError for UpdatingClient.
  • TrackingClient.toString() forwards to delegate client.

1.0.1 #

  • Automatic Content-Length header when body is specified (in ConsoleClient).

1.0.0+1 #

  • Fix: cleanup of past clients in UpdatingClient.

1.0.0 #

BREAKING CHANGES

  • Request.body is used instead of bodyStream and bodyBytes.
  • Stream<List<int>> inputs are no longer supported, use restartable FutureOr<Stream<List<int>>> StreamFn() instead.
  • Single Response constructor, body become an untyped holder (use bodyAsStream if migrating uses).

Other updates

  • Explicit expiration, and optional on-exception expiration in UpdatingClient.
  • Support form-encoded values as request body.
  • Support File with Request.body on ConsoleClient.
  • Support native request types with Request.body and Response.body on BrowserClient.

0.6.0 #

  • Support close({bool force}) on the API (and on console).
  • Support Response.done to indicate when the underlying input stream has been read and completed.
  • TrackingClient to keep track of ongoing and completed request count (with content read support).
  • UpdatingClient to automatically recreate client resources (or rotate proxies) after some use.

0.5.1 #

  • Code update: Dart 2.1(-dev) lints.

0.5.0 #

  • Dart 2

0.4.4+1 #

  • Fix header override bug.

0.4.3 #

  • Record redirect info (when available).
  • Response.requestAddress to have the address where the request was opened at.
  • BREAKING: Response.remoteAddress renamed to responseAddress.

0.4.2 #

  • Better Headers handling.
  • Request properties: persistentConnection, followRedirects, maxRedirects.
  • ConsoleClient properties: idleTimeout, maxConnectionsPerHost, autoUncompress, userAgent.
  • Response.remoteAddress (in ConsoleClient).

0.4.1 #

  • Enabled Dart2 Preview for analysis.

0.4.0 #

  • Fix deprecated API use.
  • Fix header wrapping in requests.
  • Default header values in ConsoleClient.

0.3.1 #

  • Added http proxy option to the console client.

0.3.0 #

  • Removed dependency on http package.

0.2.2 #

  • Add executor support to rate-limit the clients.

0.2.1 #

  • Add curl support.

0.2.0 #

Breaking changes:

  • instead of exporting the http package, http_client provides its own API

    • console and browser clients continue to use the http package
    • preparation to support node_io for apps that want to be packaged as a single binary (e.g. .exe)
    • preparation to support the Fetch API (e.g. in service workers)
  • removed the awkward newHttpClient() methods.

0.1.0 #

  • Exporting classes from the http package (version: ^0.1.13).

0.1.0+1 #

  • Exporting streaming request and response.

example/example.dart

import 'dart:async';

import 'package:http_client/console.dart';

Future main() async {
  final client = new ConsoleClient();
  final rs = await client.send(new Request('GET', 'https://www.example.com/'));
  final textContent = await rs.readAsString();
  print(textContent);
  await client.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  http_client: ^1.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:http_client/http_client.dart';
  
Version Uploaded Documentation Archive
1.0.3 Feb 17, 2019 Go to the documentation of http_client 1.0.3 Download http_client 1.0.3 archive
1.0.2 Feb 15, 2019 Go to the documentation of http_client 1.0.2 Download http_client 1.0.2 archive
1.0.1 Feb 14, 2019 Go to the documentation of http_client 1.0.1 Download http_client 1.0.1 archive
1.0.0+1 Feb 13, 2019 Go to the documentation of http_client 1.0.0+1 Download http_client 1.0.0+1 archive
1.0.0 Feb 11, 2019 Go to the documentation of http_client 1.0.0 Download http_client 1.0.0 archive
0.6.0 Feb 10, 2019 Go to the documentation of http_client 0.6.0 Download http_client 0.6.0 archive
0.5.1 Jan 16, 2019 Go to the documentation of http_client 0.5.1 Download http_client 0.5.1 archive
0.5.0 Aug 12, 2018 Go to the documentation of http_client 0.5.0 Download http_client 0.5.0 archive
0.4.4+1 Jun 19, 2018 Go to the documentation of http_client 0.4.4+1 Download http_client 0.4.4+1 archive
0.4.4 Jun 19, 2018 Go to the documentation of http_client 0.4.4 Download http_client 0.4.4 archive

All 21 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
79
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Apr 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:http_client/http_client.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
buffer ^1.0.0 1.0.6
executor >=2.0.0 <3.0.0 2.1.2
meta ^1.0.0 1.1.7
Transitive dependencies
path 1.6.2
stack_trace 1.9.3
Dev dependencies
pedantic ^1.0.0
test ^1.3.0