ApiWrapper<T extends GuardModel> class
A generic wrapper for API calls that automatically parses JSON responses into strongly typed models.
This class works with models that extend GuardModel.
It uses a provided fromJson factory to safely convert
API responses into Dart objects.
Example:
final api = ApiWrapper<UserModel>(
apiClient: client,
modelName: "UserModel",
fromJson: (json) => UserModel.fromJson(json),
);
final user = await api.get("/user/1");
Constructors
-
ApiWrapper({required dynamic apiClient, required String modelName, required T fromJson(Map<
String, dynamic> )}) - Creates an ApiWrapper instance.
Properties
- apiClient → dynamic
-
The API client used to perform network requests.
final
-
fromJson
→ T Function(Map<
String, dynamic> ) -
Factory function used to convert JSON into a model instance.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- modelName → String
-
The name of the model used for debugging and error reporting.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
get(
String url) → Future< T?> - Fetches a single object from the API and parses it into a model.
-
getList(
String url) → Future< List< T> > - Fetches a list of objects from the API and parses them into models.
-
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