api_request_handler 0.0.1
api_request_handler: ^0.0.1 copied to clipboard
A package for handling API requests with Dio with cache functionality and auto cancel duplicate requests.
API Service #
A lightweight and efficient Dart/Flutter package for handling API requests with optional response caching. Ideal for apps that need consistent, streamlined API access with performance optimization via local cache storage.
✨ Features #
- Simple API request handling using Dio
- Built-in request caching support
- Automatic duplicate request cancellation
- Support for GET, POST, PUT, DELETE, and other HTTP methods
- Easily pluggable into any Flutter project
- Customizable cache expiry
🚀 Getting started #
Prerequisites #
- Flutter 3.10+
- Add
api_serviceto yourpubspec.yaml:
dependencies:
api_service:
path: ../path_to/api_service
Initialization #
ApiService.initialize(
baseUrl: 'https://api.example.com',
enableLogging: true,
cacheEnabled: true,
);
📦 Usage #
final response = await ApiService.get('/users', queryParameters: {
'page': 1,
});
// Optional: Clear specific cache
ApiService.clearCache('/users');
// Optional: Refresh request
final refreshed = await ApiService.get('/users', forceRefresh: true);
📁 Example #
See the /example directory for a working Flutter integration demo.
📚 Additional information #
- This package uses
Hivefor caching (can be extended to other solutions). - Issues and contributions are welcome.
- For suggestions or help, reach out to the package maintainer.