http_plus

pub.dev ci All Contributors pub points popularity likes GitHub issues GitHub stars GitHub forks

http_plus is a drop-in replacement for http with HTTP/2 goodies! Under the hood, it wraps http2 to make it compatible with APIs of http. Additionally, it fallbacks to HTTP/1.1 if H2 is not supported by the server.

CREDIT: This is a fork of http2_client package, which is no longer maintained.

This package is in active development. Any contribution, idea, criticism or feedback is welcomed.

Quick links

Packagehttps://pub.dev/packages/http_plus
API Docshttps://pub.dev/documentation/http_plus/latest/
Git Repohttps://github.com/daadu/http_plus
Issue Trackerhttps://github.com/daadu/http_plus/issues

Using

The easiest way to use this library is via the top-level functions. They allow you to make individual HTTP requests with minimal hassle:

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

void main() async {
  final url = Uri.https('example.com', '/whatsit/create');
  final body = {'name': 'doodle', 'color': 'blue'};
  // Await http post request
  final response = await http.post(url, body: body);
  print('Response status: ${response.statusCode}');
  print('Response body: ${response.body}');
  // Close all open connection - if not required
  http.closeAllConnections();
}

For more detail on it check API docs of top-level functions.

Underneath it uses a default client with maxOpenConnection set as 8, this client is re-used among all top-level functions. If you want to have more fine-control over the client, then you can define a custom HttpPlusClient:

import 'package:http_plus/http_plus.dart';

void main() async {
  final client = HttpPlusClient(
    enableHttp2: true,
    context: SecurityContext(withTrustedRoots: true),
    badCertificateCallback: (cert, host, port) => false,
    connectionTimeout: Duration(seconds: 15),
    autoUncompress: true,
    maintainOpenConnections: true,
    maxOpenConnections: -1,
    enableLogging: false,
  );

  final url = Uri.https('example.com', '/whatsit/create');
  final body = {'name': 'doodle', 'color': 'blue'};
  // Await http post request
  final response = await client.post(url, body: body);
  print('Response status: ${response.statusCode}');
  print('Response body: ${response.body}');
  // Close all open connection
  client.close();
}

For more details on it check API docs of HttpPlusClient.

Todo

  • Web platform support (use BrowserClient directly)
  • Automatic testing
  • Handle HTTP/2 server side push
  • API to check if the request was handled by HTTP/2 client or downgraded
  • Allow user to customize logic for connection re-cycling
  • API to close connection to particular socket
  • Live web demo

Contribute

Check the Todo section above, before you begin with any contribution.

  1. You'll need a GitHub account.
  2. Fork the repository.
  3. Pick an issue to work on from issue tracker.
  4. Implement it.
  5. Add your name and email in authors section in pubspec.yaml file.
  6. Send merge request.
  7. Star this project.
  8. Become a hero!!

Features and bugs

Please file feature requests and bugs at the issue tracker.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Harsh Bhikadia

💻 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

Libraries

http_plus
Library that provides HTTP Client that can speak HTTP/2.