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. ResponseType? responseType,
  11. String? tag,
  12. bool? retryable,
  13. Map<String, dynamic>? extra,
  14. bool showLoader = true,
  15. 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))),
);

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 or a tag, since cancelling one caller must not cancel the other, and when you pass a progress callback, which only one caller's request can drive.

Per-call retry and extras — on every request method:

  • retryable overrides the method's idempotency for this one call. true lets it be retried like a GET — for a read-only POST, such as a GraphQL query — still within RetryPolicy.maxRetries, retryableStatusCodes and retryIf. false never retries it, not even on a 429 or 503. null (the default) leaves it to the method.
  • extra is copied into RequestOptions.extra, where retryIf, your interceptors and the observer can read it. The flag is there too, under RetryPolicy.retryableKey.
await api.post(
  endpoint: '/graphql',
  data: query,
  retryable: true,                  // GetBalance only reads
  extra: {'operation': 'GetBalance'},
);

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,
  ResponseType? responseType,
  String? tag,
  bool? retryable,
  Map<String, dynamic>? extra,
  bool showLoader = true,
  bool dedupe = true,
}) {
  return _respond(
    HttpMethod.get,
    endpoint,
    data: data,
    params: params,
    headers: headers,
    tag: tag,
    retryable: retryable,
    extra: extra,
    cancelToken: cancelToken,
  );
}