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

A Dio wrapper to implement logging and caching.

Dio API Handler #

This library provides a simplified way to handle API requests using the Dio package in Flutter. It includes built-in caching, logging, and error handling.

Features #

  • Dio Integration: Provides a seamless integration with Dio for HTTP requests.
  • Caching: Built-in caching mechanism using dio_cache_interceptor.
  • Logging: Detailed request and response logging.
  • Error Handling: Comprehensive error handling with descriptive messages.
  • cURL Representation: Generate cURL commands for debugging.

Installation #

Add the following dependencies to your pubspec.yaml file:

dependencies:
dio_api_handler:
path: ../ # Adjust the path according to your project structure

Usage #

Setting Up #

To use the DioAPIHandler, you need to create a class that extends it:

import 'package:dio_api_handler/dio_api_handler.dart';

class MyApiHandler extends DioAPIHandler {
  @override
  Dio generateRequestConfiguration(Dio dio) {
    dio.options.baseUrl = 'https://api.example.com';
    return dio;
  }
}

Initializing Caching #

Set up caching by calling the setupAPICache method:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await DioAPIHandler.setupAPICache();
  runApp(MyApp());
}

Making Requests #

You can now make API requests using your custom API handler:

void fetchUserData() async {
  MyApiHandler apiHandler = MyApiHandler();
  try {
    Response response = await apiHandler.get('/user');
    print(response.data);
  } catch (e) {
    print('Error: $e');
  }
}

Example Project #

For a complete example, refer to the implementation in the ./example/ directory.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

0
likes
120
points
24
downloads

Publisher

unverified uploader

Weekly Downloads

A Dio wrapper to implement logging and caching.

Documentation

API reference

License

MIT (license)

Dependencies

dio, dio_cache_interceptor, dio_cache_interceptor_hive_store, flutter, path_provider, pretty_dio_logger

More

Packages that depend on dio_api_handler