https://github.com/champ96k/minimal_http_client
A Dart package based on Dio that provides minimal http client to handle HTTP services requests. A minimal http client library for network call
https://github.com/champ96k/minimal_http_client
dart dio-flutter flutter http-client pub-package
Last synced: about 2 months ago
JSON representation
A Dart package based on Dio that provides minimal http client to handle HTTP services requests. A minimal http client library for network call
- Host: GitHub
- URL: https://github.com/champ96k/minimal_http_client
- Owner: champ96k
- License: mit
- Created: 2023-07-13T06:25:40.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-13T07:47:37.000Z (almost 3 years ago)
- Last Synced: 2025-01-06T18:54:30.217Z (over 1 year ago)
- Topics: dart, dio-flutter, flutter, http-client, pub-package
- Language: C++
- Homepage: https://pub.dev/packages/minimal_http_client
- Size: 274 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Minimal HTTP Client
A Dart package based on Dio that provides minimal http client to handle HTTP services requests. A minimal http client library for network call

## Usage
[Example](https://github.com/champ96k/minimal_http_client/tree/main/example)
To use this package :
- add the dependency to your [pubspec.yaml](https://github.com/champ96k/minimal_http_client/blob/main/example/pubspec.yaml) file.
```yaml
dependencies:
flutter:
sdk: flutter
minimal_http_client: ^0.0.3
```
### How to use `minimal_http_client`
1. At your app start-up initialize below `DioHttpService` or you can also add into your `dependency injection`
```dart
final authInterceptor = AuthInterceptor(
headerCallback: () => {
'auth_token':'Bearer your_jwt_token',
'seassion_key': 'my_seassion_key',
},
);
await DioHttpService().init(authInterceptor: authInterceptor);
```
2. How to used in `repository`
```dart
class YourRepositoryName {
YourRepositoryName({required this.httpService});
/// HttpService is a dependency injection for making HTTP requests
final HttpService httpService;
///Function for getting the list of fantasy matches
Future fetchData() async {
try {
/// URL for the list of fantasy matches
final path = '${yourBaseURL}get/news/1';
/// Send a GET request to the specified URL with authorization and auth headers
final _response = await httpService.handleGetRequest(path);
/// If the response status code is between 200 and 300, parse the response data into a YourModelClass and return it
if (_response.statusCode! >= 200 && _response.statusCode! <= 300) {
final _result = YourModelClass.fromJson(_response.data);
return _result;
}
}
/// Catch DioError and throw a to your Custom error with the error message
on DioError catch (e) {
final _message = e.response?.data?['message'] ?? '';
throw _message;
}
/// Catch all other exceptions and throw a CustomError with the error message
catch (e) {
throw '$e';
}
}
}
```
### Created & Maintained By
[Tushar Nikam](https://champ96k.github.io)