ikame_dio_client 1.0.0
ikame_dio_client: ^1.0.0 copied to clipboard
A powerful Http Client for Dart, which supports Interceptors, Refresh Token, Request Cancellation, Timeout etc.
ikame_dio_client #
ikame_dio_client
is a Flutter package that simplifies HTTP requests using Dio. It provides an easy-to-use client with configuration options and interceptor support for seamless API integration.
Features #
- Simplified HTTP client configuration with
DioConfigs
- Support for adding custom interceptors
- Easy GET, POST, PUT, DELETE requests
- Customizable base URL
Installation #
Add ikame_dio_client
to your pubspec.yaml
file:
dependencies:
ikame_dio_client: ^1.0.0
Then run:
flutter pub get
Usage #
Basic Example #
import 'package:ikame_dio_client/ikame_dio_client.dart';
void main() async {
final dioClient = DioClient(dioConfigs: DioConfigs(baseUrl: 'base-url'));
dioClient.addInterceptors([
AuthorizationInterceptor(dioClient: dioClient),
]);
dioClient.getData('/endpoints').then((value) {
print(value.toString());
}).onError((error, stackTrace) {
print(error.toString());
});
}
Explanation #
-
Create a DioClient instance:
final dioClient = DioClient(dioConfigs: DioConfigs(baseUrl: 'base-url'));
The
DioClient
is initialized with abaseUrl
for API requests. -
Add interceptors:
dioClient.addInterceptors([ AuthorizationInterceptor(dioClient: dioClient), ]);
Add custom interceptors like
AuthorizationInterceptor
for handling authentication or logging. -
Make an HTTP request:
dioClient.getData('/endpoint') .then((value) { print(value.toString()); }) .onError((error, stackTrace) { print(error.toString()); });
Use the
getData
method to fetch data from the specified endpoint.
API Reference #
DioClient #
Constructor
DioClient({required DioConfigs dioConfigs});
dioConfigs
: Configuration for the Dio client, including the base URL.
Methods
-
addInterceptors(List<Interceptor> interceptors)
- Add custom interceptors to the Dio client.
-
getData(String endpoint)
- Perform a GET request to the specified endpoint.
DioConfigs #
Constructor
DioConfigs({required String baseUrl});
baseUrl
: The base URL for all API requests.
AuthorizationInterceptor #
Constructor
AuthorizationInterceptor({required DioClient dioClient});
dioClient
: The Dio client instance.
Contributions #
Contributions are welcome! Feel free to open issues or submit pull requests to improve this package.
License #
ikame_dio_client
is released under the MIT License. See LICENSE for more details.