get method

  1. @override
Future<Either<Failure, Response>> get({
  1. required String endpoint,
  2. Object? data,
  3. Map<String, dynamic>? params,
  4. Duration? receiveTimeout,
  5. Duration? sendTimeout,
  6. Map<String, String>? headers,
  7. ProgressCallback? onSendProgress,
  8. ProgressCallback? onReceiveProgress,
  9. CancelToken? cancelToken,
  10. bool showLoader = true,
  11. CachePolicy? cachePolicy,
  12. Duration? cacheMaxAge,
  13. bool dedupe = true,
})
override

Sends a GET request to endpoint.

Use for fetching resources that don't require a request body. Query parameters go in params.

Returns Right(Response) on success, Left(Failure) on any error (network, timeout, 4xx/5xx, no internet).

Example:

final result = await _api.get(
  endpoint: '/users',
  params: {'page': 1, 'limit': 20},
);

result.fold(
  (failure) => emit(ErrorState(failure.message)),
  (response) => emit(LoadedState(UserListModel.fromJson(response.data))),
);

Caching. Omit cachePolicy and the project-wide ApiConfig.defaultCachePolicy applies — itself CachePolicy.networkOnly unless changed, which ignores the cache entirely. Anything else stores successful responses and can serve them back; see CachePolicy. cacheMaxAge bounds how old a cached entry may be before it counts as a miss.

A project can forbid caching outright with ApiConfig(cacheEnabled: false), which overrides whatever is passed here.

De-duplication. Two identical GETs in flight at the same time share one network call by default. Pass dedupe: false to force a separate request. Automatically skipped when you supply your own cancelToken, since cancelling one caller must not cancel the other.

Implementation

@override
Future<Either<Failure, Response>> get({
  required String endpoint,
  Object? data,
  Map<String, dynamic>? params,
  Duration? receiveTimeout,
  Duration? sendTimeout,
  Map<String, String>? headers,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
  CancelToken? cancelToken,
  bool showLoader = true,
  CachePolicy? cachePolicy,
  Duration? cacheMaxAge,
  bool dedupe = true,
}) {
  return _respond(HttpMethod.get, endpoint,
      data: data, params: params, headers: headers);
}