DfHttpClientConfig constructor

DfHttpClientConfig({
  1. required String baseApiUrl,
  2. Encoding? encoding,
  3. Map<String, String> headers = const {},
  4. int timeout = 10,
  5. bool retryApiCall = true,
  6. bool waitForTokenRefresh = true,
  7. int maxRetryAttempts = 3,
  8. Future<Result<String, Exception>> refreshToken()?,
  9. int maxDelayMs = 60000,
  10. Random? random,
  11. Future<bool> internetConnectionCheck()?,
})

Creates a new DfHttpClientConfig instance.

baseApiUrl is required and should be the base URL for your API.

  • encoding: Optional request/response encoding (e.g. UTF-8).
  • headers: Default headers added to every request.
  • timeout: Request timeout in seconds (default: 10).
  • retryApiCall: Whether failed API calls should automatically retry.
  • waitForTokenRefresh: Whether requests should wait until token refresh completes.
  • maxRetryAttempts: Maximum number of retry attempts for failed requests.
  • refreshToken: Callback used to refresh tokens if authentication fails.
  • maxDelayMs: Represent the maximum waiting time on API retry. Default set to 60000ms
  • internetConnectionCheck Check if the device is really connected to the internet by default it check if the 'example.com' is available, the custom logic can be implemented

  • random: Provide a "seeded" Random in tests so that the retry delay is predictable

Implementation

DfHttpClientConfig({
  required this.baseApiUrl,
  this.encoding,
  this.headers = const {},
  this.timeout = 10,
  this.retryApiCall = true,
  this.waitForTokenRefresh = true,
  this.maxRetryAttempts = 3,
  this.refreshToken,
  this.maxDelayMs = 60000,
  Random? random,
  Future<bool> Function()? internetConnectionCheck,
})
    : _rand = random ?? Random(),
      hasInternetConnection = internetConnectionCheck??_hasInternetConnection;