dahttp 3.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

Dahttp #

HTTP wrapper for Dart with integrated logger design to be used for REST APIs.

Installation #

Add the following dependencies to your pubspec.yaml:

dependencies: 
  dahttp: ^3.0.1

Example #

Future<void> main() async {
  final GetDogCeo getDogCeo = GetDogCeo();
  final HttpResult<DogCeo> result = await getDogCeo.call();

  // checking boolean properties
  if (result.success) {
    print('Success: ${result.data.url}');
  } else if (result.error) {
    print('Error: ${result.response.statusCode}');
  } else if (result.hasException) {
    print('Exception: ${result.exception}');
  }

  // passing callbacks (named parameters)
  result.handle(onSuccess: (DogCeo dog, Response response) {
    print('Success: ${dog.url}');
  }, onError: (Response response) {
    print('Error: ${response.statusCode}');
  }, onException: (dynamic exception) {
    print('Exception: $exception');
  });

  // passing callbacks (chained notation)
  result.onSuccess((DogCeo dog, Response response) {
    print('Success: ${dog.url}');
  }).onError((Response response) {
    print('Error: ${response.statusCode}');
  }).onException((dynamic exception) {
    print('Exception: $exception');
  });

  // passing callbacks (cascade notation)
  result
    ..onSuccess((DogCeo dog, Response response) {
      print('Success: ${dog.url}');
    })
    ..onError((Response response) {
      print('Error: ${response.statusCode}');
    })
    ..onException((dynamic exception) {
      print('Exception: $exception');
    });
}
class GetDogCeo extends ValuedHttpClient<DogCeo> {
  Future<HttpResult<DogCeo>> call() =>
      super.get('https://dog.ceo/api/breeds/image/random');

  @override
  DogCeo convert(Response response) => DogCeo.fromJson(response.body);
}
class DogCeo {
  final String url;

  const DogCeo(this.url);

  static DogCeo fromJson(String json) {
    final dynamic data = jsonDecode(json);

    return DogCeo(data['message']);
  }
}

[1.0.0] - 2019-06-23

  • Added first prototype

[1.1.0] - 2019-06-23

  • Refactored API

[1.2.0] - 2019-06-23

  • Added automated tests

[1.3.1] - 2019-06-24

  • Added new methods to HttpResult
  • Renamed value to data in HttpResult

[1.4.0] - 2019-06-27

  • Added lint rules

[1.4.1] - 2019-07-01

  • HTTP client and HTTP result improvements

[1.5.0] - 2019-07-04

  • Added more methods to handle the response

[1.6.0] - 2019-07-04

  • Added handler when error or exception

[1.6.1] - 2019-07-04

  • Improved failure handler

[1.7.0] - 2019-07-07

  • Improved HTTP logger

[1.8.0] - 2019-07-07

  • Added query parameters

[1.9.0] - 2019-07-09

  • Added path parameters

[1.9.1] - 2019-07-09

  • Added host parameter

[1.9.2] - 2019-07-12

  • Added method to check for status codes

[1.9.3] - 2019-07-13

  • Fixed type of parameters

[1.9.4] - 2019-07-20

  • Fixed typo

[1.9.5] - 2019-07-20

  • Added method to check for Internet connection

[2.0.0] - 2019-07-22

  • Logging exceptions

[2.1.0] - 2019-07-30

  • Added alter method

[2.2.0] - 2019-08-01

  • Improved DefaultHttpLogger

[3.0.0] - 2019-09-11

  • Added status method
  • Added request method
  • Code refactoring and renaming

[3.0.1] - 2019-09-11

  • Added hasResponse method

example/README.md

Example #

Example available in the main README.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dahttp: ^3.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dahttp/dahttp.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
52
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:dahttp/dahttp.dart with components: io.

Health issues and suggestions

Document public APIs. (-1 points)

91 out of 91 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
http ^0.12.0+2 0.12.0+2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
pedantic 1.8.0+1
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.6.4