ApiService class

ApiService is the core HTTP client service that handles all API communications. It wraps around Dio HTTP client and provides additional features like:

  • Automatic authentication token management
  • Built-in caching system
  • Standardized error handling
  • Request/Response logging
  • Automatic retry and timeout configurations

This service must be initialized once before use with init() method. It provides standard HTTP methods: GET, POST, PUT, DELETE with consistent response handling.

Constructors

ApiService()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

dio → Dio
Returns the configured Dio instance. Throws StateError if service is not initialized.
no setter

Static Methods

delete<T>({required String endpoint, T fromJson(dynamic)?, dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, bool? invalidateCache = true}) Future<ResponseResultsModel<T>>
Performs HTTP DELETE request for removing resources. Returns ResponseResultsModel with data and request details.
get<T>({required String endpoint, T fromJson(dynamic)?, Map<String, dynamic>? queryParameters, Object? data, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, ProgressCallback? onSendProgress, bool? enableCachingRequest}) Future<ResponseResultsModel<T>>
Performs HTTP GET request with optional caching support. Returns ResponseResultsModel with data and request details.
init({required String baseUrl, String? boxNameCaching, bool? enableCaching, Map<String, dynamic>? headers, bool enableLogging = false, String? getToken()?, VoidCallback? onUnauthorized, Duration? connectTimeout, Duration? receiveTimeout, Dio? dioClient}) Future<void>
Initializes the ApiService with required configuration. Must be called once before using any HTTP methods.
post<T>({required String endpoint, T fromJson(dynamic)?, dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, ProgressCallback? onSendProgress, bool? invalidateListCache}) Future<ResponseResultsModel<T>>
Performs HTTP POST request for creating new resources. Returns ResponseResultsModel with data and request details.
put<T>({required String endpoint, T fromJson(dynamic)?, required dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onReceiveProgress, ProgressCallback? onSendProgress, bool? updateCache = true}) Future<ResponseResultsModel<T>>
Performs HTTP PUT request for updating existing resources. Returns ResponseResultsModel with data and request details.