JetApiService class abstract

Abstract base class for HTTP API interactions Enhanced with singleton pattern and response model wrapper Provides a comprehensive networking solution with:

  • All HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS)
  • Custom interceptors support
  • Default headers management
  • Generic JSON response decoding with ResponseModel wrapper
  • Singleton pattern for efficient resource management
  • Enhanced error handling and caching support

Constructors

JetApiService.new(Ref ref)

Properties

baseUrl String
Base URL for all API requests
no setter
connectTimeout Duration
Timeout configuration
no setter
currentHeaders Map<String, dynamic>
Get current headers
no setter
defaultHeaders Map<String, dynamic>
Default headers that will be added to all requests
no setter
dio Dio
Access to the underlying Dio instance for advanced usage
no setter
globalCacheOptions Options?
Cache options configuration (can be overridden)
no setter
hashCode int
The hash code for this object.
no setterinherited
httpClientAdapter HttpClientAdapter?
HTTP client adapter (can be overridden for HTTP/2, etc.)
no setter
interceptors List<Interceptor>
Custom interceptors to be added to the Dio instance
no setter
receiveTimeout Duration
no setter
ref Ref
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sendTimeout Duration
no setter
serviceId String
API service identifier for singleton management
no setter

Methods

addHeader(String key, String value) → void
Add a header that will persist for all subsequent requests
addInterceptor(Interceptor interceptor) → void
Add an interceptor at runtime
cancelRequests([String? reason]) → void
Cancel all pending requests
clearHeaders() → void
Clear all headers except default ones
createCancelToken() CancelToken
Create a new cancel token
delete<T>(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, T decoder(dynamic)?, bool useResponseModel = true}) Future<ResponseModel<T>>
Enhanced DELETE request with ResponseModel wrapper
download(String urlPath, String savePath, {void onReceiveProgress(int, int)?, Map<String, dynamic>? queryParameters, CancelToken? cancelToken, bool deleteOnError = true, String lengthHeader = Headers.contentLengthHeader, Options? options}) Future<Response>
Download file
get<T>(String path, {Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, void onReceiveProgress(int, int)?, T decoder(dynamic)?, bool useResponseModel = true}) Future<ResponseModel<T>>
Enhanced GET request with ResponseModel wrapper
HEAD request
network<T>({required Future<ResponseModel<T>> request(), T? fallback, bool throwOnError = true}) Future<T>
Provides a clean interface for making requests with automatic response handling
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
optionsRequest(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? requestOptions, CancelToken? cancelToken}) Future<Response>
OPTIONS request
patch<T>(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, void onSendProgress(int, int)?, void onReceiveProgress(int, int)?, T decoder(dynamic)?, bool useResponseModel = true}) Future<ResponseModel<T>>
Enhanced PATCH request with ResponseModel wrapper
post<T>(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, void onSendProgress(int, int)?, void onReceiveProgress(int, int)?, T decoder(dynamic)?, bool useResponseModel = true}) Future<ResponseModel<T>>
Enhanced POST request with ResponseModel wrapper
put<T>(String path, {dynamic data, Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, void onSendProgress(int, int)?, void onReceiveProgress(int, int)?, T decoder(dynamic)?, bool useResponseModel = true}) Future<ResponseModel<T>>
Enhanced PUT request with ResponseModel wrapper
removeHeader(String key) → void
Remove a header
removeInterceptor(Interceptor interceptor) → void
Remove an interceptor
toString() String
A string representation of this object.
inherited
updateHeaders(Map<String, String> headers) → void
Update multiple headers at once
upload<T>(String path, FormData formData, {Map<String, dynamic>? queryParameters, Options? options, CancelToken? cancelToken, void onSendProgress(int, int)?, T decoder(dynamic)?}) Future<ResponseModel<T>>
Upload files with multipart/form-data

Operators

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

Static Methods

getInstance<T extends JetApiService>(String serviceId, T creator()) → T
Get singleton instance of an API service