PrimekitNetworkClient class final

A pre-configured Dio HTTP client for Primekit-powered applications.

PrimekitNetworkClient wraps Dio with:

  • RetryInterceptor for automatic exponential-backoff retries on 5xx / network errors.
  • A structured logging interceptor that records every request/response.
  • An optional auth-interceptor slot — supply onAuthToken to inject a bearer token on every request.
  • Consistent ApiResponse return types so callers never deal with raw DioExceptions.
final client = PrimekitNetworkClient(
  baseUrl: 'https://api.example.com',
  headers: {'X-App-Version': '1.0.0'},
  onAuthToken: () async =>
      await SecureStorage.instance.read('access_token'),
);

final response = await client.get<User>(
  '/users/me',
  parser: (json) => User.fromJson(json as Map<String, dynamic>),
);

response.when(
  loading: () {},  // never returned by these methods
  success: (user) => print(user.name),
  failure: (err)  => print(err.userMessage),
);

Constructors

PrimekitNetworkClient({required String baseUrl, Map<String, String> headers = const {}, Duration timeout = const Duration(seconds: 30), Future<String?> onAuthToken()?, int maxRetries = 3, Duration retryInitialDelay = const Duration(seconds: 1)})
Creates a PrimekitNetworkClient.

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

delete<T>(String path, {Object? body, Map<String, Object?>? queryParameters, T parser(dynamic json)?}) Future<ApiResponse<T>>
Performs a DELETE request to path.
get<T>(String path, {Map<String, Object?>? queryParameters, T parser(dynamic json)?}) Future<ApiResponse<T>>
Performs a GET request to path.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch<T>(String path, {Object? body, Map<String, Object?>? queryParameters, T parser(dynamic json)?}) Future<ApiResponse<T>>
Performs a PATCH request to path with optional body.
post<T>(String path, {Object? body, Map<String, Object?>? queryParameters, T parser(dynamic json)?}) Future<ApiResponse<T>>
Performs a POST request to path with optional body.
put<T>(String path, {Object? body, Map<String, Object?>? queryParameters, T parser(dynamic json)?}) Future<ApiResponse<T>>
Performs a PUT request to path with optional body.
toString() String
A string representation of this object.
inherited

Operators

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