api_service_plus 0.0.1
api_service_plus: ^0.0.1 copied to clipboard
A customizable API wrapper around Dio.
Api Service Wrapper
A lightweight and customizable API service wrapper built on top of Dio.
This package helps you handle common networking tasks such as authentication, token refresh, caching, logging, and retries without repeating boilerplate code.
β¨ Features
β Attach access tokens automatically via tokenProvider
π Auto refresh expired tokens with refreshTokenHandler
β»οΈ Retry failed requests with exponential backoff
π¦ Built-in caching using dio_cache_interceptor
πͺ΅ Optional logging of requests & responses
β Throws a clean ApiException for easy error handling
π¦ Installation
Add this to your pubspec.yaml:
dependencies: api_service_wrapper: ^0.0.1
Then run:
flutter pub get
π Usage
import 'package:api_service_wrapper/api_service_wrapper.dart';
void main() async { final api = ApiService( baseUrl: "https://jsonplaceholder.typicode.com", tokenProvider: () async => "your-access-token", refreshTokenHandler: () async => "new-access-token", addLogging: true, );
try { final response = await api.get("/posts/1"); print("Response data: ${response.data}"); } on ApiException catch (e) { print("API failed: $e"); } }
π§ͺ Error Handling
try { final response = await api.get("/users"); } on ApiException catch (e) { print("Error: ${e.message} (code: ${e.statusCode})"); }
π Changelog
See CHANGELOG.md for release notes.
π License
This project is licensed under the MIT License.