Connect-Dart is a slim library for using generated, type-safe, and idiomatic Dart clients to communicate with your app's servers using Protocol Buffers (Protobuf). It works with the Connect, gRPC, and gRPC-Web protocol.
Given a simple Protobuf schema, Connect-Dart generates idiomatic dart:
Click to expand eliza.connect.dart
extension type ElizaServiceClient(connect.Transport _transport) {
Future<connectrpcelizav1eliza.SayResponse> say(
connectrpcelizav1eliza.SayRequest input, {
connect.Header? header,
connect.AbortSignal? signal,
Function(connect.Header)? onHeader,
Function(connect.Header)? onTrailer,
}) {
return connect.Client(_transport).unary(
const connect.Spec(
'/$name/Say',
connect.StreamType.unary,
connectrpcelizav1eliza.SayRequest.new,
connectrpcelizav1eliza.SayResponse.new,
),
input,
signal: signal,
header: header,
onHeader: onHeader,
onTrailer: onTrailer,
);
}
Stream<connectrpcelizav1eliza.ConverseResponse> converse(
Stream<connectrpcelizav1eliza.ConverseRequest> input, {
connect.Header? header,
connect.AbortSignal? signal,
Function(connect.Header)? onHeader,
Function(connect.Header)? onTrailer,
}) {
return connect.Client(_transport).bidi(
const connect.Spec(
'/$name/Converse',
connect.StreamType.bidi,
connectrpcelizav1eliza.ConverseRequest.new,
connectrpcelizav1eliza.ConverseResponse.new,
),
input,
signal: signal,
header: header,
onHeader: onHeader,
onTrailer: onTrailer,
);
}
Stream<connectrpcelizav1eliza.IntroduceResponse> introduce(
connectrpcelizav1eliza.IntroduceRequest input, {
connect.Header? header,
connect.AbortSignal? signal,
Function(connect.Header)? onHeader,
Function(connect.Header)? onTrailer,
}) {
return connect.Client(_transport).server(
const connect.Spec(
'/$name/Introduce',
connect.StreamType.server,
connectrpcelizav1eliza.IntroduceRequest.new,
connectrpcelizav1eliza.IntroduceResponse.new,
),
input,
signal: signal,
header: header,
onHeader: onHeader,
onTrailer: onTrailer,
);
}
}
This code can then be integrated with just a few lines:
void main() async {
late ElizaServiceClient elizaClient;
final response = await elizaClient.say(SayRequest(sentence: "Hey!"))
print(response.message);
}
That’s it! You no longer need to manually define request/response models, write encode/decode methods, specify the exact path of your request, nor worry about the underlying networking transport for your applications!
Head over to our quick start tutorial to get started. It only takes ~10 minutes to complete a working chat app that uses Connect-Dart!
Comprehensive documentation for everything, including interceptors, streaming, and error handling is available on the connectrpc.com website.
Option | Type | Default | Details |
---|---|---|---|
keep_empty_files |
Boolean | false |
Generate files even if the proto file doesn't have any service definitions |
Example apps are available in /examples
.
We'd love your help making Connect better!
Extensive instructions for building the library and generator plugins locally,
running tests, and contributing to the repository are available in our
CONTRIBUTING.md
guide. Please check it out
for details.
- connect-swift: Swift clients for idiomatic gRPC & Connect RPC
- connect-kotlin: Idiomatic gRPC & Connect RPCs for Kotlin
- connect-es: Type-safe APIs with Protobuf and TypeScript.
- connect-go: Service handlers and clients for GoLang
- conformance: Connect, gRPC, and gRPC-Web interoperability tests
This project is in alpha, and we will make a few changes as we gather feedback from early adopters.
Offered under the Apache 2 license.