easy_api_call 0.0.7
easy_api_call: ^0.0.7 copied to clipboard
A reusable HTTP API service with token management.
๐ easy_api_call #
A flexible and developer-friendly Flutter package for handling HTTP network requests using Dio with automatic token-based authentication, refresh token handling, and full support for all major HTTP methods (GET, POST, PUT, DELETE, PATCH).
Built and maintained with โค๏ธ
Contributed with โค๏ธ
โจ Features #
- ๐ Auto Token Refresh: Automatically refresh access tokens when they expire (on 401 responses).
- ๐ Optional Authentication: Easily toggle between authenticated and unauthenticated requests.
- ๐ Supports All HTTP Methods: Clean, unified interface for GET, POST, PUT, DELETE, and PATCH.
- ๐ง Dynamic Configuration: Configure base URL, access token, refresh token, and refresh URL at runtime.
- ๐งพ Integrated Logging: Uses
PrettyDioLoggerfor clean, structured logging of all request/response data. - โ ๏ธ SSL Certificate Bypass (for dev): Allows development with self-signed certificates (optional).
- ๐ช Interceptor-based Error Handling: Easily hook into Dio's interceptors to customize error and retry logic.
๐ Usage #
import 'package:api_service_plus/api_service_plus.dart';
void main() async {
final api = ApiService();
api.configure(
baseUrl: 'https://your-api.com',
token: 'access_token',
refreshToken: 'refresh_token',
refreshTokenUrl: 'https://your-api.com/auth/refresh',
);
try {
// Perform authenticated GET request
final response = await api.get('/user/profile', requiresAuth: true);
print(response.data);
} catch (e) {
print('Request failed: $e');
}
}
---