coffee_http 0.2.6+1

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

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);
    }
  });
}

Use this package as a library

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

Alternatively, your editor might support pub 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...

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

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <2.0.0