http_kit 0.1.0 copy "http_kit: ^0.1.0" to clipboard
http_kit: ^0.1.0 copied to clipboard

A portable HTTP client with an onion middleware pipeline: retry with full-jitter backoff, timeouts, bearer authentication and metadata headers, on Cronet, Cupertino or the browser stack.

example/example.dart

// ignore_for_file: avoid_print, an example prints to show the result.

import 'package:http_kit/http_kit.dart';

Future<void> main() async {
  final api = ApiClient(
    baseUrl: () => Uri.parse('https://api.example.com/v1'),
    middlewares: <ApiClientMiddleware>[
      RetryMiddleware(backoff: const RetryBackoff(maxRetries: 3)).call,
      const TimeoutMiddleware(connectTimeout: Duration(seconds: 10)).call,
      MetadataMiddleware(headers: const {'X-App-Version': '1.0.0'}).call,
    ],
  );

  try {
    final user = await api.get('/users/42').toJson();
    print(user['name']);
  } on ApiClientException catch (e) {
    print('${e.code}: ${e.message}');
  } finally {
    api.close();
  }
}
1
likes
140
points
95
downloads

Documentation

API reference

Publisher

verified publisherdmitrii.app

Weekly Downloads

A portable HTTP client with an onion middleware pipeline: retry with full-jitter backoff, timeouts, bearer authentication and metadata headers, on Cronet, Cupertino or the browser stack.

Topics

#http #middleware #retry #cronet #quic

License

MIT (license)

Dependencies

core_model, cronet_http, cupertino_http, flutter, http, meta

More

Packages that depend on http_kit