chopper 0.0.3

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

chopper

Chopper is an http client generator using source_gen and inspired from Retrofit.

Usage

Generator

Add the generator to your dev dependencies

dev_dependencies:
  build_runner: ^0.8.0
  chopper_generator: ^0.0.1

Define and Generate your API

// my_service.dart

import "dart:async";
import 'package:chopper/chopper.dart';

part "my_service.g.dart";

@ServiceDefinition("MyService", baseUrl: "/resources")
abstract class MyServiceDefinition {
  @Get(url: "/{id}")
  Future<Response> getResource(@Path() String id);

  @Get(url: "/", headers: const {"foo": "bar"})
  Future<Response<Map>> getMapResource(@Query() String id);
}

then run the generator

pub run build_runner build

Use it

Create a Chopper client and inject your generated api.

final chopper = new ChopperClient(
    baseUrl: "http://localhost:8000",
    converter: const JsonConverter(),
    services: [
      // the generated service
      new MyService()
    ],
    interceptors: [
      new Headers(const {"Content-Type": "application/json"}),
    ]);

final myService = chopper.service(MyService) as MyService;

final response = await myService.getMapResource("1");

More example

Issue Tracker

Changelog

0.0.3

  • fix type applyHeaders
  • fix toHttpRequest builder

0.0.2

  • the generated extension is now *.chopper.dart

  • rename ServiceDefinition to ChopperApi

  • rename ChopperClient.services field to ChopperClient.apis

0.0.1

  • Initial version, created by Stagehand

example/main.dart

import 'package:chopper/chopper.dart';
import 'definition.dart';

main() async {
  final chopper = new ChopperClient(
      baseUrl: "http://localhost:8000",
      converter: const JsonConverter(),
      apis: [
        // the generated service
        new MyService()
      ],
      /* ResponseInterceptorFunc | RequestInterceptorFunc | ResponseInterceptor | RequestInterceptor */
      interceptors: [
        new Headers(const {"Content-Type": "application/json"}),
      ]);

  final myService = chopper.service(MyService) as MyService;

  final response = await myService.getMapResource("1");
  print(response.body);
}

1. Depend on it

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


dependencies:
  chopper: "^0.0.3"

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:chopper/chopper.dart';
        
Version Uploaded Documentation Archive
0.0.3 Apr 24, 2018 Go to the documentation of chopper 0.0.3 Download chopper 0.0.3 archive
0.0.2 Apr 8, 2018 Go to the documentation of chopper 0.0.2 Download chopper 0.0.2 archive
0.0.1 Apr 7, 2018 Go to the documentation of chopper 0.0.1 Download chopper 0.0.1 archive

Analysis

We analyzed this package on Apr 24, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

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

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:chopper/chopper.dart.

Suggestions

  • 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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <2.0.0
http ^0.11.0 0.11.3+16
meta ^1.1.2 1.1.2
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
test ^0.12.0