rspl_network_manager 0.0.1 copy "rspl_network_manager: ^0.0.1" to clipboard
rspl_network_manager: ^0.0.1 copied to clipboard

A Flutter plugin that simplifies networking with configurable logging, token persistence, mock API support, automatic token refresh, connectivity checks, and proxy configuration.

RSPL Network Manager #

pub package License: MIT

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 #

  • ๐Ÿ“ 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_storage with 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 INTERNET permission in AndroidManifest.xml.
  • iOS: No explicit permissions required for basic networking.
  • macOS: Add com.apple.security.network.client entitlement.

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": "john@mail.com",
  "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:

Run checks before push:

  • dart format .
  • flutter analyze
  • flutter 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 #

Github โ€ข Website

8
likes
160
points
161
downloads

Publisher

verified publisherrishabhsoft.com

Weekly Downloads

A Flutter plugin that simplifies networking with configurable logging, token persistence, mock API support, automatic token refresh, connectivity checks, and proxy configuration.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (license)

Dependencies

connectivity_plus, dio, dio_smart_retry, flutter, flutter_secure_storage

More

Packages that depend on rspl_network_manager