Search packages, repositories and app categories

Package detailsv0.0.4+1

dio_interceptors

Implements interceptors for you use on Dio package.

30-day downloads
14
Likes
14
Pub points
30

Install package

flutter pub add dio_interceptors

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

Dio interceptors is a package that extends the Dio HTTP client by providing a simple way to implement request and response interceptors. These interceptors allow developers to modify requests before they are sent, handle responses after they are received, or manage errors globally. Ideal for adding authentication tokens, logging, retry logic, or transforming data across all API calls. It integrates seamlessly with Dio, enhancing its functionality without requiring significant changes to existing code. The package is lightweight and focused on improving HTTP interaction workflows in Flutter applications.

Use cases

  • Adding auth headers to requests
  • Logging HTTP traffic
  • Handling API error responses
  • Implementing retry mechanisms
  • Transforming request/response data

Key features

  • Easy integration with Dio
  • Supports request and response interceptors
  • Global error handling
  • Lightweight and minimal overhead
  • Simple API for chaining interceptors

Suitable for

  • Flutter apps using Dio for HTTP requests
  • Projects needing centralized HTTP logic
  • Developers implementing authentication flows
  • Apps requiring request/response transformation
  • Teams wanting consistent API interaction patterns

Considerations

  • Requires Dio to be already integrated
  • Limited to Dio-based HTTP operations
  • No built-in support for non-Dio clients
  • May require understanding of interceptor patterns
  • Not suitable for standalone HTTP clients

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

dio_interceptors

A interceptors to use on Dio.

INTERCEPTORS

Interceptor Mock

You use for mock API requests.


void main() {
  Dio dio = Dio();

  var mockData = {
     "/test" : {
       "name" : "Gabul DEV",
       "site" : "https://gabul.dev"
     }
   };
   dio.interceptors.add(InterceptorMock(mockData));

   void getData() async{
       var res = await dio.get("/test");
      print(res.data["name"])// "Gabul DEV" 
      print(res.data["site"])// "https://gabul.dev"); 
   }
    
    getData();
}

Interceptor Token

You can use for add JWT all requests

Future<String> token() async{
  //Implements your logic here
  return jwt;
}

dio.interceptors.add(InterceptorToken(token: () async => await token()))

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.