minimal_http_client 0.0.3 copy "minimal_http_client: ^0.0.3" to clipboard
minimal_http_client: ^0.0.3 copied to clipboard

A Dart package based on Dio that provides minimal http client to handle HTTP services requests. A minimal http client library for network call

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

Bitbucket open issues

Usage #

Example

To use this package :

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
    final authInterceptor = AuthInterceptor(
        headerCallback: () => {
          'auth_token':'Bearer your_jwt_token',
          'seassion_key': 'my_seassion_key',
        },
      );
      await DioHttpService().init(authInterceptor: authInterceptor);
  1. How to used in repository


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<YourModelClass> 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


0
likes
140
pub points
0%
popularity

Publisher

unverified uploader

A Dart package based on Dio that provides minimal http client to handle HTTP services requests. A minimal http client library for network call

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

dio, dio_http2_adapter, flutter, http, package_info, pretty_dio_logger

More

Packages that depend on minimal_http_client