http_plus
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
Package | https://pub.dev/packages/http_plus |
API Docs | https://pub.dev/documentation/http_plus/latest/ |
Git Repo | https://github.com/daadu/http_plus |
Issue Tracker | https://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 for basic stats for each request - HTTP/2 vs 1.1, Connection Reuse vs New, etc
- 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.
- You'll need a GitHub account.
- Fork the repository.
- Pick an issue to work on from issue tracker.
- Implement it.
- Add your name and email in
authors
section inpubspec.yaml
file. - Send merge request.
- Star this project.
- 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 💻 🤔 |
Luka S 💻 |
busslina 💻 |
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.