smart_request 0.1.1 copy "smart_request: ^0.1.1" to clipboard
smart_request: ^0.1.1 copied to clipboard

A lightweight Dart package for resilient API calls with retry, backoff, timeout, and fallback.

example/lib/main.dart

import 'dart:async';

import 'package:dio/dio.dart';
import 'package:smart_request/smart_request.dart';

Future<void> main() async {
  final dio = Dio();

  try {
    final response = await smartRequest<Response<dynamic>>(
      () => dio.get('https://mpe359c3a29a2750bd3b.free.beeceptor.com/call'),
      fallback: () =>
          dio.get('https://mpe359c3a29a2750bd3b.free.beeceptor.com/fallback'),
      config: SmartRequestConfig(
        maxRetries: 3,
        initialDelay: const Duration(seconds: 1),
        maxDelay: const Duration(seconds: 8),
        backoffFactor: 2.0,
        jitter: true,
        timeout: const Duration(seconds: 5),
        onError: (e, s) => print('Error: $e'),
        onRetry: (attempt, nextDelay, e, s) =>
            print('Retry #$attempt after $nextDelay due to $e'),
      ),
    );

    print('✅ Response data: ${response.data}');
  } catch (e) {
    print('❌ Final error: $e');
  }
}
0
likes
160
points
28
downloads

Documentation

API reference

Publisher

verified publishermwaqas.mobvers.com

Weekly Downloads

A lightweight Dart package for resilient API calls with retry, backoff, timeout, and fallback.

Repository (GitHub)
View/report issues

Topics

#http #retry #backoff #networking

License

MIT (license)

More

Packages that depend on smart_request