cosmic 1.0.1

  • Readme
  • Changelog
  • Installing
  • 0

Cosmic #

Simple work with REST JSON API for DART

Usage #

A simple usage example:

import 'package:http/http.dart' as http;
import 'package:cosmic/converters/cosmic_converters.dart';
import 'package:cosmic/annotations/cosmic_annotations.dart';
import 'package:cosmic/cosmic.dart' as Cosmic;   
class Fixer {
    String base;
    String date;
    Map<String, double> rates;
  converter: const JsonConverter()
class FixerClient extends Cosmic.Client {
  Future<Fixer> latest({@Query("base") String base = "USD"});
main() async {
  Fixer latest = await fixerClient.latest();

A middleware:

FixerClient client = new FixerClient()
  ..use((request, next) {
    print("${request.httpMethod} ${request.url}");
    request.headers["token"] = "12345";

A converter:

import 'package:jsonx/jsonx.dart' as jsonx;

class JsonConverter extends Converter {
  const JsonConverter();

  dynamic decode(String data, {Type type}) => jsonx.decode(data, type: type);

  String encode(object) => jsonx.encode(object);

(check example/placeholder_client.dart for more)

Generate #

dart:mirror is absent from flutter
use cosmic:generate in order to generate the api impl pre runtime

$ pub run cosmic:generate -i example/clients/def/placeholder.dart -c PlaceholderClient -o example/clients/impl -w true

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.0.3 #

  • Request's middlewares

0.0.2 #

  • Separate encode/decode to converters

0.0.1 #

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

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

  cosmic: ^1.0.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:cosmic/cosmic.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.

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.

Analysis 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


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