RSPL Network Manager
RSPLNetworkManager is a production-ready networking wrapper for Flutter apps, built on top of Dio. It simplifies HTTP requests with built-in logging, token management, offline support, and automatic token refreshing.
It abstracts away common boilerplate code associated with HTTP clients, offering a clean API for handling authentication, logging, error handling, and connectivity states. It is designed to be modular and easily extensible.
Table of Contents
- Features
- Platform Support
- Requirements
- Getting Started
- Usage
- Configuration
- Folder Structure
- Contributing
- License
Features
- ๐ Configurable Logging: Debug your network traffic with ease using configurable logging levels (request/response headers, body, errors).
- ๐ Secure Token Storage: Seamless token persistence using
flutter_secure_storagewith automatic injection into requests. - ๐ Auto Token Refresh: Built-in mechanism to handle 401 errors and refresh expired access tokens automatically.
- ๐ ๏ธ Mock API Support: Develop faster by mocking API responses when the backend isn't ready.
- ๐ก Connectivity Awareness: Automatically checks for internet connection before making requests to prevent unnecessary failures.
- ๐ Proxy Support: Easy configuration for proxy settings during debugging.
- ๐งช Testable: Designed with dependency injection in mind, making it easy to unit test your networking logic.
Platform Support
- Android โ API Level: 21+
- iOS โ iOS 12.0+
- macOS โ macOS 10.14+
- Windows โ Windows 10+
- Linux โ Any modern distribution
- Web โ All modern browsers
Requirements
- Dart: >=3.5.0 <4.0.0
- Flutter: Flutter 3.24.0+
- Dio: ^5.0.0
Permissions
- Android: Add
INTERNETpermission inAndroidManifest.xml. - iOS: No explicit permissions required for basic networking.
- macOS: Add
com.apple.security.network.cliententitlement.
Getting Started
1. Install
Add the dependency to your pubspec.yaml:
dependencies:
rspl_network_manager: ^0.0.1
Then run:
flutter pub get
2. Import
import 'package:rspl_network_manager/rspl_network_manager.dart';
Usage
Minimal Setup
// Create a DioFactory instance
final dioFactory = DioFactory('https://api.example.com');
// Create a Dio client
final dio = dioFactory.create();
Advanced Setup with Interceptors
import 'package:dio/dio.dart';
import 'package:rspl_network_manager/rspl_network_manager.dart';
import 'package:get_it/get_it.dart';
void main() {
// 1. Configure Dio factory
const dioFactory = DioFactory('https://api.example.com');
// 2. Setup Token Interceptor
final tokenInterceptor = TokenInterceptor(
tokenPersister: GetIt.I<ITokenPersister>(),
exceptionList: ['/auth/login', '/auth/register'], // Endpoints that don't need tokens
);
// 3. Setup Logger Interceptor
final loggerInterceptor = WSLoggerInterceptor(
requestBody: true,
requestHeader: true,
error: true,
responseHeader: true,
);
// 4. Register Dio client
GetIt.I.registerSingleton<Dio>(
dioFactory.create()
..interceptors.add(ConnectivityInterceptor())
..interceptors.add(tokenInterceptor)
..interceptors.add(loggerInterceptor),
);
}
Configuration
| Component | Description |
|---|---|
DioFactory |
Factory class to create pre-configured Dio instances. |
TokenInterceptor |
Injects Authorization header with Bearer token. |
WSLoggerInterceptor |
Logs request and response details to console. |
ConnectivityInterceptor |
Checks for internet connectivity before request. |
TokenRefreshInterceptorWrapper |
Handles 401 errors and refreshes tokens. |
ITokenPersister |
Interface for persisting tokens (save, read, delete). |
Folder Structure
rspl_network_manager/
โโ lib/
โ โโ rspl_network_manager.dart # Main package export
โ โโ src/
โ โโ dio_factory.dart # Dio instance creator
โ โโ interceptors/ # Network interceptors
โ โ โโ token_interceptor.dart
โ โ โโ logger_interceptor.dart
โ โ โโ ...
โ โโ token/ # Token management
โ โ โโ token_persister.dart
โ โ โโ token_refresher.dart
โ โโ ...
โโ example/ # Complete example app
โโ test/ # Unit tests
โโ CHANGELOG.md # Version history
โโ LICENSE # MIT License
โโ README.md # Documentation
Example
For a complete example, including login, profile fetching, and token refresh, see the example directory.
Note:
The example app uses a public mock API with demo login credentials:{ "email": "[email protected]", "password": "changeme" }These credentials are provided by the Platzi Fake API and may change over time.
If the example app throws authentication or API errors, verify the latest valid credentials on the official API documentation:
https://fakeapi.platzi.com/en/rest/auth-jwt/
Contributing
Contributions welcome! Please read:
- CONTRIBUTING.md โ setup, branch strategy, commit convention
- CODE_OF_CONDUCT.md
Run checks before push:
dart format .flutter analyzeflutter test
User Privacy Notes
- This package does not collect any user information or share data with third-party services.
Author, Maintainers & Acknowledgements
- Developed by Rishabh Software.
- Thanks to the Flutter community for the amazing packages used in this project.
License
This package is licensed under the MIT License. See LICENSE for details.
Made by RSPL Team
Libraries
- rspl_network_manager
- A Flutter plugin that simplifies networking with Dio.