ApiClientService class

High-level service class for making API requests with simplified interface

This class provides static methods for common HTTP operations with sensible defaults and built-in caching support. It wraps the underlying ApiClientPlus instance with a cleaner API.

Features:

  • Static methods for easy access from anywhere
  • Built-in caching with multiple strategies
  • Automatic authentication handling
  • Request/response interception
  • Cache management utilities

Quick Start:

// Initialize first (usually in main.dart)
await ApiClientPlus().initialize(...);

// Then use anywhere in your app:
final news = await ApiClientService.get(
  '/api/news',
  useCache: true,
  cacheStrategy: ApiClientCacheStrategy.cacheThenNetwork,
);

Constructors

ApiClientService()

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 Properties

instance ApiClientPlus
Get the singleton ApiClientPlus instance
no setter

Static Methods

clearAllCache() Future<int>
Clear all cached data
clearDomainCache(String domain) Future<int>
Clear cache for a specific domain
clearExpiredCache() Future<int>
Clear only expired cache entries
clearMethodCache(String method) Future<int>
Clear cache for a specific HTTP method
delete(String path, {String? domainName, dynamic data, Map<String, dynamic>? query, Map<String, dynamic>? headers, bool requiresAuth = false, Duration? timeout, Map<String, dynamic>? customHeaders}) Future<Response>
Execute a DELETE request
get(String path, {String? domainName, Map<String, dynamic>? query, Map<String, dynamic>? headers, bool useCache = false, bool forceRefresh = false, Duration? maxStale, Duration? timeout, ApiClientCacheStrategy? cacheStrategy, Map<String, dynamic>? customHeaders}) Future<Response>
Execute a GET request with optional caching
getCacheStats() Future<Map<String, dynamic>>
Get cache statistics for monitoring and UI display
patch(String path, {String? domainName, dynamic data, Map<String, dynamic>? query, Map<String, dynamic>? headers, bool requiresAuth = false, Duration? timeout, Map<String, dynamic>? customHeaders}) Future<Response>
Execute a PATCH request
post(String path, {String? domainName, dynamic data, Map<String, dynamic>? query, Map<String, dynamic>? headers, bool requiresAuth = false, Duration? timeout, Map<String, dynamic>? customHeaders}) Future<Response>
Execute a POST request
put(String path, {String? domainName, dynamic data, Map<String, dynamic>? query, Map<String, dynamic>? headers, bool requiresAuth = false, Duration? timeout, Map<String, dynamic>? customHeaders}) Future<Response>
Execute a PUT request