Easy http request for browser and server.
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));
}
class ResourceModel {
String name;
ResourceModel(this.name);
ResourceModel.fromMap(Map json) {
name = json["name"];
}
Map toMap() => { "name": name };
String toString() => toMap().toString();
}
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);
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);
}
});
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);
}
});
}
Add this to your package's pubspec.yaml file:
dependencies:
coffee_http: "^0.2.6+1"
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.
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 |
|
|
0.2.6 | May 31, 2016 |
|
|
0.2.5 | May 12, 2016 |
|
|
0.2.4 | May 11, 2016 |
|
|
0.2.3+2 | May 11, 2016 |
|
|
0.2.3+1 | May 11, 2016 |
|
|
0.2.3 | May 11, 2016 |
|
|
0.2.2 | May 11, 2016 |
|
|
0.2.1 | Apr 29, 2016 |
|
|
0.2.0 | Apr 26, 2016 |
|
|
We analyzed this package on Apr 9, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
0 | / 100 |
Health:
Code health derived from static analysis.
[more]
|
97 | / 100 |
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
13 | / 100 |
Overall score:
Weighted score of the above.
[more]
|
32 |
Detected platforms: Flutter, web, other
No platform restriction found in libraries.
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.
Fix analysis and formatting issues.
Analysis or formatting checks reported 9 hints.
Run
dartfmt
to formatlib/coffee.dart
.Run
dartfmt
to formatlib/src/coffee.dart
.Similar analysis of the following files failed:
lib/src/middleware.dart
(hint)lib/src/request.dart
(hint)lib/src/response.dart
(hint)lib/src/utils.dart
(hint)
Use analysis_options.yaml
.
Rename old
.analysis_options
file toanalysis_options.yaml
.
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.6 | ||
charcode | 1.1.1 | ||
collection | 1.14.9 | ||
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 |