RestApiClientImpl constructor

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

Constructor for initializing the RestApiClientImpl with required options and interceptors.

Implementation

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

  /// 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
}