mercury_client 1.1.4

  • Readme
  • Changelog
  • Installing
  • 73

Mercury Client #

A Simple Dart HTTP client with Web and Native support.

Usage #

A simple usage example:

import 'package:mercury_client/mercury_client.dart';
import 'dart:async';

main() async {
  
  var client = HttpClient('http://gateway.your.domain/api-1') ;

  // Calling with POST method:
  // URL: http://gateway.your.domain/api-1/call-foo?var=123
  // Content-Type: application/json
  // Body:
  // { 'content': 'any' }}
  var response = await client.post("call-foo", parameters: {'var': '123'}, body: "{ 'content': 'any' }}", contentType: 'application/json') ;
  
  if ( response.isOK ) {
    print( response.body ) ;
  }

}

HttpCache usage:

import 'package:mercury_client/mercury_client.dart';
import 'dart:async';

main() async {
  
  var client = HttpClient('http://gateway.your.domain/api-1') ;
  
  // HTTP Cache with max memory of 16M and timeout of 5min:
  var cache = HttpCache(1024*1024*16, 1000*60*5) ;

  var response = cache.getURL( 'http://host/path/to/base64/image.jpeg') ;

  if ( response.isOK ) {
    img.src = 'data:image/jpeg;base64,'+ response.body ;
  }

}

Mercury (mythology) #

Mercury is known to the Romans as Mercurius.

He is the god of financial gain, commerce, eloquence, messages, communication (including divination), travelers, boundaries, luck, trickery and thieves.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Dart free & open-source license.

1.1.4 #

  • HttpResponse.bodyType/isBodyTypeJSON
  • BearerCredential.findToken
  • fix HttpResponse.getResponseHeader()
  • getHttpMethod()
  • swiss_knife: ^2.3.9

1.1.3 #

  • swiss_knife: ^2.3.7

1.1.2 #

  • Fix HttpCache to identify requests with complex body already in cache.
  • HttpError: response body as HttpError.message.
  • swiss_knife: ^2.3.4

1.1.1 #

  • swiss_knife: ^2.3.1

1.1.0 #

  • Fix parsing of Uri path with encoded char (ex.: %20).
  • Fix automatic set of application/x-www-form-urlencoded when sending POST query parameters.
  • Retry request with network error.
  • Fix HttpCache requests with dynamic body.
  • swiss_knife: ^2.3.0

1.0.9 #

  • BearerCredential.fromJSONToken

1.0.8 #

  • HttpClient: fullPath parameter to indicate that the path is full (from root).
  • HttpClient._buildRequestAuthorization: fix case when result is a null credential.

1.0.7 #

  • JSONBodyCredential: creates a JSON body with authentication for each request.
  • HttpBody: now a request body is dynamic, it can be Map and List (automatically converted to JSON) or a normal String.

1.0.6 #

  • Public method buildRequestURL.
  • HttpCache class: handles requests cache with entries timeout and memory limit.

1.0.5 #

  • Update dependencies.
  • Code analysis.

1.0.4 #

  • Update dependencies.
  • Code analysis.

1.0.3 #

  • Add Author and License to README.

1.0.1 #

  • Code analysis

1.0.0 #

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

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


dependencies:
  mercury_client: ^1.1.4

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:mercury_client/mercury_client.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
76
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Mar 30, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6

Health issues and suggestions

Document public APIs. (-0.46 points)

269 out of 274 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.

Format lib/mercury_client.dart.

Run dartfmt to format lib/mercury_client.dart.

Format lib/src/http_cache.dart.

Run dartfmt to format lib/src/http_cache.dart.

Format lib/src/http_client.dart.

Run dartfmt to format lib/src/http_client.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/http_client_browser.dart (Run dartfmt to format lib/src/http_client_browser.dart.)
  • lib/src/http_client_io.dart (Run dartfmt to format lib/src/http_client_io.dart.)
  • lib/src/http_client_none.dart (Run dartfmt to format lib/src/http_client_none.dart.)

Maintenance suggestions

The package description is too short. (-14 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and mercury_client.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
enum_to_string ^1.0.8 1.0.9
swiss_knife ^2.3.9 2.3.9
Transitive dependencies
intl 0.16.1
path 1.6.4
resource_portable 2.1.7
typed_data 1.1.6
Dev dependencies
pedantic ^1.8.0
test ^1.6.0