EitherApiService class

EitherApiService provides functional programming approach to HTTP operations. Instead of throwing exceptions, it returns Either<Error, Success> results.

This service wraps around ApiService and transforms results into Either pattern:

  • Left side contains ServiceErrorModel for failures
  • Right side contains ResponseResultsModel for successful responses

Benefits:

  • Explicit error handling without try-catch blocks
  • Functional programming pattern for cleaner code
  • Type-safe error and success handling
  • No unexpected exceptions thrown
  • Consistent API across all HTTP methods

All methods mirror ApiService functionality but return Either results. Must be initialized before use with the init() method.

Constructors

EitherApiService()

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 Methods

delete<T>({required String endpoint, T fromJson(dynamic)?, dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, ProgressCallback? onSendProgress, bool? invalidateCache}) Future<Either<ServiceErrorModel, ResponseResultsModel<T>>>
Performs HTTP DELETE request with Either pattern result. Returns Either<ServiceErrorModel, ResponseResultsModel<T>> for explicit error handling.
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<Either<ServiceErrorModel, ResponseResultsModel<T>>>
Performs HTTP GET request with Either pattern result. Returns Either<ServiceErrorModel, ResponseResultsModel<T>> for explicit error handling.
init({required String baseUrl, String? boxNameCaching, bool? enableCaching, Map<String, dynamic>? headers, bool enableLogging = false, String? getToken()?, VoidCallback? onUnauthorized, Duration? connectTimeout, Duration? receiveTimeout}) Future<void>
Initializes the EitherApiService 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<Either<ServiceErrorModel, ResponseResultsModel<T>>>
Performs HTTP POST request with Either pattern result. Returns Either<ServiceErrorModel, ResponseResultsModel<T>> for explicit error handling.
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}) Future<Either<ServiceErrorModel, ResponseResultsModel<T>>>
Performs HTTP PUT request with Either pattern result. Returns Either<ServiceErrorModel, ResponseResultsModel<T>> for explicit error handling.