dio_api_client 1.0.0 copy "dio_api_client: ^1.0.0" to clipboard
dio_api_client: ^1.0.0 copied to clipboard

discontinued
outdated

API Client for flutter projects based on dio package.

Dio API Client #

Pub Version GitHub License

Description #

The Flutter API Client is a package designed to simplify the process of making API requests in Flutter projects. It is built on top of the popular dio package, providing a streamlined and efficient way to communicate with RESTful APIs.

Features #

  • Easy integration: The Flutter API Client is easy to integrate into your Flutter projects, allowing you to start making API requests quickly.
  • Simple configuration: The package provides a straightforward configuration process, making it easy to set up and customize your API client.
  • Support for authentication: The Flutter API Client supports various authentication methods, including token-based authentication and API key authentication.
  • Flexible request options: With the Flutter API Client, you can easily customize request options such as headers, query parameters, timeouts, and more.
  • Error handling: The package includes error handling mechanisms to handle API errors gracefully and provide meaningful error messages.

Installation #

To use the Flutter API Client in your Flutter project, add the following dependency to your pubspec.yaml file:

dependencies:
  dio_api_client: ^1.0.0

Then, run the command flutter pub get to fetch the package.

Usage #

  1. Import the package:
import 'package:dio_api_client/dio_api_client.dart';
  1. Initialize the API client:
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await DioApiClient.init();
  runApp(const MyApp());
}
  1. Make API class and extend DioApiClient:
/// * [T] is the type of the response data
class PubPackage extends DioApiClient<T> {
  @override
  Duration get cacheDuration => Duration.zero;

  @override
  String get endpoint => 'pub.flutter-io.cn/api/';

  @override
  String get path => 'packages/';

  Future<T?> getPackage(String name) async {
    final response = await get(
      dynamicPath: name,
    );
    return response.data;
  }
}

Configuration #

You can configure the API client by overriding the following methods:

/// * [T] is the type of the response data
class MainBase<T> extends DioApiClient<T> {
  @override
  List<Interceptor> get interceptors => [authInterceptor, logInterceptor];

  @override
  Duration get cacheDuration => Duration.zero;

  @override
  String get endpoint => 'pub.flutter-io.cn/api/';

  @override
  String get path => 'packages/';
}


class PubPackage extends MainBase<T> {
  Future<T?> getPackage(String name) async {
    final response = await get(
      dynamicPath: name,
    );
    return response.data;
  }
}

Contributing #

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue. Additionally, feel free to submit pull requests with bug fixes or new features.

When contributing to this project, please follow the code of conduct.

License #

This package is open source and released under the MIT License. Feel free to use, modify, and distribute the package according to the terms of the license.

Contact #

If you have any questions or inquiries about the Flutter API Client, please contact contact@mohesu.com.

Authors #

heman4t rvndsngwn

Happy coding! 💙 Flutter