dio_api_handler

Creator: coderz1093

Last updated:

0 purchases

dio_api_handler Image
dio_api_handler Images

Languages

Categories

Add to Cart

Description:

dio api handler

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
copied to clipboard
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;
}
}
copied to clipboard
Initializing Caching #
Set up caching by calling the setupAPICache method:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await DioAPIHandler.setupAPICache();
runApp(MyApp());
}
copied to clipboard
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');
}
}
copied to clipboard
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.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.