Last updated:
0 purchases
net kit
Sponsors #
A big thanks to our awesome sponsors for keeping this project going!️ Want to help out? Consider becoming a sponsor!
Contents #
Features
Getting started
Initialize
Extend the model
Sending requests
Request a Single Model
Request a List of Models
Send a Void Request
Planned Enhancements
Contributing
License
Features #
📝 Supports various HTTP methods (GET, POST, PUT, DELETE, PATCH)
🌐 Configurable base URLs for development and production
📊 Logging of network requests and responses
❗ Error handling and response validation
🛠 Parsing responses into models or lists of models using INetKitModel
Getting started #
Initialize #
Initialize the NetKitManager with the parameters:
import 'package:net_kit/net_kit.dart';
final netKitManager = NetKitManager(
baseUrl: 'https://api.<URL>.com',
devBaseUrl: 'https://dev.<URL>.com',
loggerEnabled: true,
testMode: true,
);
copied to clipboard
Extend the model #
Requests such as: requestModel andrequestList require the model to
extend INetKitModel in order to be used with the NetKitManager. By extending, INetKitModel
fromJson and toJson methods will be needed to be implemented, so the model can be serialized and
deserialized.
class TodoModel extends INetKitModel {}
copied to clipboard
Sending requests #
Request a Single Model
Future<RandomUserModel> getRandomUser() async {
try {
final result = await netKitManager.requestModel<RandomUserModel>(
path: '/api',
method: RequestMethod.get,
model: const RandomUserModel(),
);
return result;
}
/// Catch the ApiException and handle it
on ApiException catch (e) {
/// Handle the error: example is to throw the error
throw Exception(e.message);
}
}
copied to clipboard
Request a List of Models
Future<List<ProductModel>> getProducts() async {
try {
final result = await netKitManager.requestList<ProductModel>(
path: '/products',
method: RequestMethod.get,
model: const ProductModel(),
);
return result;
}
/// Catch the ApiException and handle it
on ApiException catch (e) {
/// Handle the error: example is to throw the error
throw Exception(e.message);
}
}
copied to clipboard
Send a void Request
Future<void> deleteProduct() async {
try {
await netKitManager.requestVoid(
path: '/products',
method: RequestMethod.delete,
);
return;
}
/// Catch the ApiException and handle it
on ApiException catch (e) {
/// Handle the error: example is to throw the error
throw Exception(e.message);
}
}
copied to clipboard
Planned Enhancements #
Feature
Status
Internationalization support for error messages
✅
No internet connection handling
✅
Provide basic example
✅
Provide more examples and use cases in the documentation
Multi-part form data support
Refresh Token implementation
Enhance logging capabilities with customizable log levels
Implement retry logic for failed requests
Add more tests to ensure the package is robust and reliable
Add Migration Guide for breaking changes
Contributing #
Contributions are welcome! Please open an issue
or submit a pull request.
License #
This project is licensed under the MIT License.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.