chopper 0.1.0

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

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

  • update dart sdk

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

Use this package as a library

1. Depend on it

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


dependencies:
  chopper: ^0.1.0

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 flutter 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.1.0 Aug 1, 2018 Go to the documentation of chopper 0.1.0 Download chopper 0.1.0 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
Popularity:
Describes how popular the package is relative to other packages. [more]
67
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.11.8

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 of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
http ^0.11.0 0.11.3+17
meta ^1.1.2 1.1.6
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
path 1.6.2
source_span 1.4.1
string_scanner 1.0.3
typed_data 1.1.6
Dev dependencies
test ^1.3.0