get method
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,
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, when
you pass a progress callback, which only one caller's request can drive,
and when you pass your own receiveTimeout or sendTimeout, since one
caller's deadline must not apply to another.
Per-call retry and extras — on every request method:
retryableoverrides the method's idempotency for this one call.truelets it be retried like aGET— for a read-onlyPOST, such as a GraphQL query — still withinRetryPolicy.maxRetries,retryableStatusCodesandretryIf.falsenever retries it, not even on a429or503.null(the default) leaves it to the method.extrais copied intoRequestOptions.extra, whereretryIf, your interceptors and the observer can read it. The flag is there too, underRetryPolicy.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,
);
}