BasicApiAdapter<TModel extends SynquillDataModel<TModel>> class abstract

Concrete implementation of ApiAdapterBase using Dio for HTTP requests.

This is the standard adapter provided by the library that users can extend by simply overriding baseUrl and optionally fromJson/toJson methods.

Features:

  • Complete HTTP implementation using Dio
  • Automatic JSON serialization/deserialization
  • Configurable timeouts and retry logic
  • Proper error handling with typed exceptions
  • Support for custom headers per request
  • Request/response logging

Example usage:

class EventAdapter extends BaseApiAdapter<Event> {
  @override
  Uri get baseUrl => Uri.parse('https://api.example.com/v1/');

  @override
  Event fromJson(Map<String, dynamic> json) => Event.fromJson(json);

  @override
  Map<String, dynamic> toJson(Event model) => model.toJson();
}
Inheritance
Mixed-in types

Constructors

BasicApiAdapter.new()

Properties

baseHeaders FutureOr<Map<String, String>>
HTTP headers applied to every request. Can be overridden in subclasses for model-specific headers.
no setterinherited
baseUrl Uri
Base URL for the API. Must be provided by concrete implementations. Example: Uri.parse('https://api.example.com/v1/')
no setterinherited
dio Dio
Access to the underlying Dio client.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
headersWithContentType FutureOr<Map<String, String>>
HTTP headers for operations that send data (POST, PUT, PATCH). Includes Content-Type header for JSON data. Can be overridden in subclasses for model-specific headers.
no setterinherited
logger Logger
Logger instance for this adapter.
no setterinherited
pluralType String
Plural form of the entity name for collection endpoints.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type String
Logical entity name, singular.
no setterinherited

Methods

createOne(TModel model, {Map<String, String>? headers, Map<String, dynamic>? extra}) Future<TModel?>
Creates a new item on the remote API.
override
deleteOne(String id, {Map<String, String>? headers, Map<String, dynamic>? extra}) Future<void>
Deletes an item by its ID from the remote API.
override
executeCreateRequest({required TModel model, Map<String, String>? headers, Map<String, dynamic>? extra}) Future<TModel?>
Executes a create request.
inherited
executeDeleteRequest({required String id, Map<String, String>? headers, Map<String, dynamic>? extra}) Future<void>
Executes a delete request.
inherited
executeFindAllRequest({Map<String, String>? headers, QueryParams? queryParams, Map<String, dynamic>? extra}) Future<List<TModel>>
Executes a findAll request.
inherited
executeFindOneRequest({required String id, Map<String, String>? headers, QueryParams? queryParams, Map<String, dynamic>? extra}) Future<TModel?>
Executes a findOne request.
inherited
executeReplaceRequest({required TModel model, Map<String, String>? headers, Map<String, dynamic>? extra}) Future<TModel?>
Executes a replace request.
inherited
executeRequest<T>({required String method, required Uri uri, Object? data, Map<String, String>? headers, Map<String, dynamic>? queryParameters, Map<String, dynamic>? extra}) Future<Response<T>>
Executes an HTTP request using the configured Dio client.
inherited
executeUpdateRequest({required TModel model, Map<String, String>? headers, Map<String, dynamic>? extra}) Future<TModel?>
Executes an update request.
inherited
findAll({Map<String, String>? headers, QueryParams? queryParams, Map<String, dynamic>? extra}) Future<List<TModel>>
Fetches all items from the remote API.
override
findOne(String id, {Map<String, String>? headers, QueryParams? queryParams, Map<String, dynamic>? extra}) Future<TModel?>
Fetches a single item by its ID from the remote API.
override
fromJson(Map<String, dynamic> json) → TModel
Converts a JSON map to an instance of the model TModel.
inherited
mapDioErrorToSynquillStorageException(DioException error) SynquillStorageException
Maps a DioException to the appropriate SynquillStorageException.
inherited
mergeHeaders(Map<String, String>? requestHeaders, {Map<String, dynamic>? extra}) FutureOr<Map<String, String>>
Merges base headers with request-specific headers.
inherited
mergeHeadersWithContentType(Map<String, String>? requestHeaders, {Map<String, dynamic>? extra}) FutureOr<Map<String, String>>
Merges headers with Content-Type for operations that send data.
inherited
methodForCreate({Map<String, dynamic>? extra}) String
HTTP method for creating a new entity. Default: 'POST'
inherited
methodForDelete({Map<String, dynamic>? extra}) String
HTTP method for deleting an entity. Default: 'DELETE'
inherited
methodForFind({QueryParams? queryParams, Map<String, dynamic>? extra}) String
HTTP method used by findOne / findAll operations. Default: 'GET'
inherited
methodForReplace({Map<String, dynamic>? extra}) String
HTTP method for full replacement. Default: 'PUT'
inherited
methodForUpdate({Map<String, dynamic>? extra}) String
HTTP method for partial updates. Default: 'PATCH'
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseCreateResponse(dynamic responseData, Response response) → TModel?
Parses a create response.
inherited
parseFindAllResponse(dynamic responseData, Response response) List<TModel>
Parses a findAll response.
inherited
parseFindOneResponse(dynamic responseData, Response response) → TModel?
Parses a findOne response.
inherited
parseReplaceResponse(dynamic responseData, Response response) → TModel?
Parses a replace response.
inherited
parseUpdateResponse(dynamic responseData, Response response) → TModel?
Parses an update response.
inherited
queryParamsToHttpParams(QueryParams? queryParams) Map<String, String>
Converts QueryParams to HTTP query parameters.
inherited
replaceOne(TModel model, {Map<String, String>? headers, Map<String, dynamic>? extra}) Future<TModel?>
Replaces an existing item on the remote API with full replacement.
override
toJson(TModel model) Map<String, dynamic>
Converts a model instance to a JSON map for API requests.
inherited
toString() String
A string representation of this object.
inherited
updateOne(TModel model, {Map<String, String>? headers, Map<String, dynamic>? extra}) Future<TModel?>
Updates an existing item on the remote API using partial update.
override
urlForCreate({Map<String, dynamic>? extra}) FutureOr<Uri>
Constructs the URL for creating a new model instance.
inherited
urlForDelete(String id, {Map<String, dynamic>? extra}) FutureOr<Uri>
Constructs the URL for deleting a model instance.
inherited
urlForFindAll({QueryParams? queryParams, Map<String, dynamic>? extra}) FutureOr<Uri>
Constructs the URL for fetching all model instances.
inherited
urlForFindOne(String id, {QueryParams? queryParams, Map<String, dynamic>? extra}) FutureOr<Uri>
Constructs the URL for fetching/updating/deleting a single model instance.
inherited
urlForReplace(String id, {Map<String, dynamic>? extra}) FutureOr<Uri>
Constructs the URL for replacing an existing model instance.
inherited
urlForUpdate(String id, {Map<String, dynamic>? extra}) FutureOr<Uri>
Constructs the URL for updating an existing model instance.
inherited

Operators

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