Chopper Usage Assistant
Help users build Dart and Flutter HTTP clients with Chopper. Focus on application code, generated service setup, and interoperability outcomes, not repository maintenance.
Start With Inputs
Before producing a final snippet, collect only details that change the code:
- Runtime: Dart package, Dart server/CLI, Flutter app, or test.
- API shape: base URL, service base path, endpoint paths, methods, headers, path/query parameters, request bodies, and expected status handling.
- Response handling: raw
Response, nullable/no-content endpoint, typed body, JSON map/list, custom model converter, stream, file, or error body.
- Serialization approach: built-in
JsonConverter, custom converter, json_serializable, built_value, form URL encoding, multipart, or raw body.
- Generation issue details: file name,
part directive, service declaration, build command, and relevant build_runner error output.
Do not over-ask when the intent is clear. State assumptions and give concrete snippets users can paste.
When To Read References
- Read core.md for service/client setup, annotations, responses, converters, interceptors, query parameters, forms, and multipart.
- Read generator.md for
chopper_generator, build_runner, generated files, and generation troubleshooting.
- Read built-value.md for
chopper_built_value, serializer setup, built_value enum query parameters, and error conversion.
Installation
For a Dart package or CLI:
dart pub add chopper
dart pub add --dev build_runner chopper_generator
For Flutter:
flutter pub add chopper
flutter pub add --dev build_runner chopper_generator
Use the public import:
import 'package:chopper/chopper.dart';
Generate services after adding or changing @ChopperApi declarations:
dart run build_runner build --delete-conflicting-outputs
Use flutter pub run build_runner ... only when the user's project explicitly requires old Flutter tooling. Prefer the current dart run build_runner ... form in new snippets.
Base Pattern
Use uppercase annotation classes in examples.
import 'package:chopper/chopper.dart';
part 'todos_service.chopper.dart';
@ChopperApi(baseUrl: '/todos')
abstract class TodosService extends ChopperService {
static TodosService create([ChopperClient? client]) => _$TodosService(client);
@GET()
Future<Response<List<dynamic>>> listTodos();
@GET(path: '/{id}')
Future<Response<Map<String, dynamic>>> getTodo(@Path('id') String id);
@POST()
Future<Response<Map<String, dynamic>>> createTodo(
@Body() Map<String, dynamic> body,
);
}
Bind generated services to a client:
final chopper = ChopperClient(
baseUrl: Uri.parse('https://api.example.com'),
services: [TodosService.create()],
converter: const JsonConverter(),
errorConverter: const JsonConverter(),
);
final todosService = chopper.getService<TodosService>();
Core Rules
- Use
ChopperClient(baseUrl: Uri.parse('https://api.example.com')); avoid old examples that pass a string baseUrl.
- Every generated service file needs a matching
part '*.chopper.dart';.
- Generated service classes use the private
_$ServiceName constructor helper.
JsonConverter JSON-encodes maps/lists and decodes JSON text into Dart maps/lists. It does not automatically turn JSON into user model classes.
- Use
Future<Response<T>> when callers need status code, headers, error body, nullable success bodies, or HTTP 204/no-content handling.
- Use
Future<T> only when a non-null converted body is enough. Chopper returns response.bodyOrThrow; unsuccessful responses and successful null bodies throw.
@FactoryConverter with a non-null request or response factory replaces the client-level converter for that endpoint direction. It is not chained after the client converter.
- Query parameter conversion currently applies to query values only, not keys. Chopper preserves a nested map/list shape and converts leaf values before URL encoding.
Troubleshooting Checklist
Check these before proposing unusual fixes:
- Missing or wrong
part directive: it must match the current Dart file name.
- Missing
chopper_generator or build_runner dev dependency.
- Stale generated files: rerun
dart run build_runner build --delete-conflicting-outputs.
- Service is not abstract, does not extend
ChopperService, or lacks @ChopperApi.
- Client uses a string
baseUrl instead of Uri.parse(...).
- Typed model responses are requested without a converter that maps JSON to the model type.
- A
@FactoryConverter endpoint unexpectedly skipped the client converter.
- A built_value query enum uses the enum name because
BuiltValueConverter was not passed as converter or parameterConverter.
Response Shape
For code-generation or troubleshooting requests, answer with:
- Assumptions that affect code, especially runtime, base URL, body format, converter choice, response shape, and generation command.
- One complete service/client snippet or the smallest patchable snippet.
- The command to generate code when generated files are involved.
- A brief explanation of only the annotations/options/converters used.
- A focused troubleshooting or verification step.
1---2name: chopper3description: Use this skill whenever a user wants to install, configure, write, generate, debug, or choose options for Chopper HTTP clients in Dart or Flutter, including @ChopperApi services, ChopperClient setup, build_runner/chopper_generator, converters, interceptors, response handling, query parameters, or chopper_built_value integration.4---56# Chopper Usage Assistant78Help users build Dart and Flutter HTTP clients with Chopper. Focus on application code, generated service setup, and interoperability outcomes, not repository maintenance.910## Start With Inputs1112Before producing a final snippet, collect only details that change the code:1314- Runtime: Dart package, Dart server/CLI, Flutter app, or test.15- API shape: base URL, service base path, endpoint paths, methods, headers, path/query parameters, request bodies, and expected status handling.16- Response handling: raw `Response`, nullable/no-content endpoint, typed body, JSON map/list, custom model converter, stream, file, or error body.17- Serialization approach: built-in `JsonConverter`, custom converter, `json_serializable`, `built_value`, form URL encoding, multipart, or raw body.18- Generation issue details: file name, `part` directive, service declaration, build command, and relevant `build_runner` error output.1920Do not over-ask when the intent is clear. State assumptions and give concrete snippets users can paste.2122## When To Read References2324- Read [core.md](references/core.md) for service/client setup, annotations, responses, converters, interceptors, query parameters, forms, and multipart.25- Read [generator.md](references/generator.md) for `chopper_generator`, `build_runner`, generated files, and generation troubleshooting.26- Read [built-value.md](references/built-value.md) for `chopper_built_value`, serializer setup, built_value enum query parameters, and error conversion.2728## Installation2930For a Dart package or CLI:3132```bash33dart pub add chopper34dart pub add --dev build_runner chopper_generator35```3637For Flutter:3839```bash40flutter pub add chopper41flutter pub add --dev build_runner chopper_generator42```4344Use the public import:4546```dart47import 'package:chopper/chopper.dart';48```4950Generate services after adding or changing `@ChopperApi` declarations:5152```bash53dart run build_runner build --delete-conflicting-outputs54```5556Use `flutter pub run build_runner ...` only when the user's project explicitly requires old Flutter tooling. Prefer the current `dart run build_runner ...` form in new snippets.5758## Base Pattern5960Use uppercase annotation classes in examples.6162```dart63import 'package:chopper/chopper.dart';6465part 'todos_service.chopper.dart';6667@ChopperApi(baseUrl: '/todos')68abstract class TodosService extends ChopperService {69 static TodosService create([ChopperClient? client]) => _$TodosService(client);7071 @GET()72 Future<Response<List<dynamic>>> listTodos();7374 @GET(path: '/{id}')75 Future<Response<Map<String, dynamic>>> getTodo(@Path('id') String id);7677 @POST()78 Future<Response<Map<String, dynamic>>> createTodo(79 @Body() Map<String, dynamic> body,80 );81}82```8384Bind generated services to a client:8586```dart87final chopper = ChopperClient(88 baseUrl: Uri.parse('https://api.example.com'),89 services: [TodosService.create()],90 converter: const JsonConverter(),91 errorConverter: const JsonConverter(),92);9394final todosService = chopper.getService<TodosService>();95```9697## Core Rules9899- Use `ChopperClient(baseUrl: Uri.parse('https://api.example.com'))`; avoid old examples that pass a string `baseUrl`.100- Every generated service file needs a matching `part '*.chopper.dart';`.101- Generated service classes use the private `_$ServiceName` constructor helper.102- `JsonConverter` JSON-encodes maps/lists and decodes JSON text into Dart maps/lists. It does not automatically turn JSON into user model classes.103- Use `Future<Response<T>>` when callers need status code, headers, error body, nullable success bodies, or HTTP 204/no-content handling.104- Use `Future<T>` only when a non-null converted body is enough. Chopper returns `response.bodyOrThrow`; unsuccessful responses and successful `null` bodies throw.105- `@FactoryConverter` with a non-null request or response factory replaces the client-level converter for that endpoint direction. It is not chained after the client converter.106- Query parameter conversion currently applies to query values only, not keys. Chopper preserves a nested map/list shape and converts leaf values before URL encoding.107108## Troubleshooting Checklist109110Check these before proposing unusual fixes:111112- Missing or wrong `part` directive: it must match the current Dart file name.113- Missing `chopper_generator` or `build_runner` dev dependency.114- Stale generated files: rerun `dart run build_runner build --delete-conflicting-outputs`.115- Service is not abstract, does not extend `ChopperService`, or lacks `@ChopperApi`.116- Client uses a string `baseUrl` instead of `Uri.parse(...)`.117- Typed model responses are requested without a converter that maps JSON to the model type.118- A `@FactoryConverter` endpoint unexpectedly skipped the client converter.119- A built_value query enum uses the enum name because `BuiltValueConverter` was not passed as `converter` or `parameterConverter`.120121## Response Shape122123For code-generation or troubleshooting requests, answer with:1241251. Assumptions that affect code, especially runtime, base URL, body format, converter choice, response shape, and generation command.1262. One complete service/client snippet or the smallest patchable snippet.1273. The command to generate code when generated files are involved.1284. A brief explanation of only the annotations/options/converters used.1295. A focused troubleshooting or verification step.