api_service_plus 0.0.1 copy "api_service_plus: ^0.0.1" to clipboard
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.

2
likes
120
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

A customizable API wrapper around Dio.

Documentation

API reference

License

MIT (license)

Dependencies

dio, dio_cache_interceptor, flutter

More

Packages that depend on api_service_plus