RestApiClientImpl constructor

RestApiClientImpl({
  1. required RestApiClientOptions options,
  2. ExceptionOptions? exceptionOptions,
  3. LoggingOptions? loggingOptions,
  4. AuthOptions? authOptions,
  5. CacheOptions? cacheOptions,
  6. RetryOptions? retryOptions,
  7. bool enableDeduplication = false,
  8. List<Interceptor> interceptors = const [],
})

Creates a new RestApiClientImpl instance.

The options parameter is required and must include at least the base URL. All other parameters are optional and have sensible defaults.

The interceptors parameter allows adding custom Dio interceptors that will be executed before the built-in refresh token and retry interceptors.

Implementation

RestApiClientImpl({
  required RestApiClientOptions options,
  ExceptionOptions? exceptionOptions,
  LoggingOptions? loggingOptions,
  AuthOptions? authOptions,
  CacheOptions? cacheOptions,
  RetryOptions? retryOptions,
  bool enableDeduplication = false,
  List<Interceptor> interceptors = const [],
}) {
  _options = options; // Set client options
  _exceptionOptions =
      exceptionOptions ?? ExceptionOptions(); // Set exception options
  _loggingOptions =
      loggingOptions ?? const LoggingOptions(); // Set logging options
  _authOptions =
      authOptions ?? const AuthOptions(); // Set authentication options
  _cacheOptions = cacheOptions ?? const CacheOptions(); // Set cache options
  _retryOptions = retryOptions ?? const RetryOptions(); // Set retry options
  _deduplicationEnabled = enableDeduplication; // Set deduplication flag

  /// Initialize Dio with base URL
  _dio = Dio(BaseOptions(baseUrl: _options.baseUrl));

  /// Set the appropriate HTTP client adapter depending on the platform
  _dio.httpClientAdapter = getAdapter();

  // Initialize various handlers
  exceptionHandler = ExceptionHandler(exceptionOptions: _exceptionOptions);
  authHandler = AuthHandler(
    dio: _dio,
    options: options,
    exceptionOptions: _exceptionOptions,
    authOptions: _authOptions,
    loggingOptions: _loggingOptions,
    exceptionHandler: exceptionHandler,
  );
  cacheHandler = CacheHandler(
    loggingOptions: _loggingOptions,
    cacheOptions: _cacheOptions,
  );

  // Add custom interceptors
  _addInterceptors(interceptors);
  _configureLogging(); // Configure logging for requests/responses
  _configureCertificateOverride(); // Setup certificate overriding for development
}