coffee_http 0.2.6+1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 35

coffee_http

Easy http request for browser and server.

Usage

A simple usage example:

import "package:coffee_http/coffee.dart";

main() {

    Get request = new Get("http://localhost/data", middlewares: [
        JSON_CONTENT_TYPE,
        ENCODE_TO_JSON_MIDDLEWARE,
        DECODE_FROM_JSON_MIDDLEWARE,
    ]);
    
    request.execute().then((CoffeeResponse res) => print(res.decodedBody));

}

More complexe example:

Example

Model

class ResourceModel {
  String name;

  ResourceModel(this.name);

  ResourceModel.fromMap(Map json) {
    name = json["name"];
  }

  Map toMap() => { "name": name };

  String toString() => toMap().toString();

}

Define Requests

CoffeeRequester api = new CoffeeRequester(middlewares: [
        new ResolveApiMiddleware("http://localhost", 9000, subPath: "/api"),
        LOGGER_MIDDLEWARE,
        JSON_CONTENT_TYPE,
        ENCODE_TO_JSON_MIDDLEWARE,
        DECODE_FROM_JSON_MIDDLEWARE,
    ], client: client);

api["resources"] = new Get("/resources", decoder: ResourceModel.listDecoder);
api["resources"]["read"] = new Get("/{name}", decoder: ResourceModel.decoder);
api["resources"]["create"] = new Post("/create",
    encoder: ResourceModel.encoder, decoder: ResourceModel.decoder);

Use it

initApi();

api["resources"].execute().then((CoffeeResponse _res) {
print(_res.decodedBody as List<ResourceModel>);
});

api["resources"]["create"]
  .execute(body: new ResourceModel()
    ..name = "toto"
    ..capacity = 3)
  .then((CoffeeResponse _res) {
if (_res.statusCode == 200) {
  ResourceModel resource = _res.decodedBody as ResourceModel;
  print(resource);
}
});

api["resources"]["read"]
  .execute(parameters: {"name": "toto"}).then((CoffeeResponse _res) {
if (_res.statusCode == 200) {
  ResourceModel resource = _res.decodedBody as ResourceModel;
  print(resource);
}
});

Changelog

0.0.1

  • Initial version, created by Stagehand

example/main.dart

/**
 * Created by lejard_h on 25/04/16.
 */

import "dart:async";
import "package:coffee_http/coffee.dart";
import "models/models.dart";
import "api/api.dart";

Future<Null> main() async {
  initApi();

  api["resources"].execute().then((CoffeeResponse _res) {
    print(_res.decodedBody as List<ResourceModel>);
  });

  api["resources"]["create"]
      .execute(body: new ResourceModel()
        ..name = "truc"
        ..capacity = 3)
      .then((CoffeeResponse _res) {
    if (_res.statusCode == 200) {
      ResourceModel resource = _res.decodedBody as ResourceModel;
      print(resource);
    }
  });

  api["resources"]["read"].execute(parameters: {"name": "truc"}).then((CoffeeResponse _res) {
    if (_res.statusCode == 200) {
      ResourceModel resource = _res.decodedBody as ResourceModel;
      print(resource);
    }
  });
}

1. Depend on it

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


dependencies:
  coffee_http: "^0.2.6+1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:coffee_http/coffee.dart';
        
Version Uploaded Documentation Archive
0.2.6+1 May 31, 2016 Go to the documentation of coffee_http 0.2.6+1 Download coffee_http 0.2.6+1 archive
0.2.6 May 31, 2016 Go to the documentation of coffee_http 0.2.6 Download coffee_http 0.2.6 archive
0.2.5 May 12, 2016 Go to the documentation of coffee_http 0.2.5 Download coffee_http 0.2.5 archive
0.2.4 May 11, 2016 Go to the documentation of coffee_http 0.2.4 Download coffee_http 0.2.4 archive
0.2.3+2 May 11, 2016 Go to the documentation of coffee_http 0.2.3+2 Download coffee_http 0.2.3+2 archive
0.2.3+1 May 11, 2016 Go to the documentation of coffee_http 0.2.3+1 Download coffee_http 0.2.3+1 archive
0.2.3 May 11, 2016 Go to the documentation of coffee_http 0.2.3 Download coffee_http 0.2.3 archive
0.2.2 May 11, 2016 Go to the documentation of coffee_http 0.2.2 Download coffee_http 0.2.2 archive
0.2.1 Apr 29, 2016 Go to the documentation of coffee_http 0.2.1 Download coffee_http 0.2.1 archive
0.2.0 Apr 26, 2016 Go to the documentation of coffee_http 0.2.0 Download coffee_http 0.2.0 archive

All 11 versions...

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
98 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
30 / 100
Overall score:
Weighted score of the above. [more]
35

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Suggestions

  • Use constrained dependencies.

    The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: http.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <2.0.0
http >=0.11.3 0.11.3+16
Transitive dependencies
async 2.0.3
charcode 1.1.1
collection 1.14.5
http_parser 3.1.1
path 1.5.1
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.5
Dev dependencies
browser ^0.10.0+2
dogma_codegen >=0.0.2 <0.1.0
grinder ^0.8.0+2
test >=0.12.0 <0.13.0