ska_connect 1.0.3

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

Support library for making request with the Connect (connect.build) protocol. Intended for use with generated code.

pub package package publisher Unit tests license

Dart support package for the Connect protocol. This is not intended for direct use, but for use with generated code. It currently supports unary requests and the protocol client can be customized by implementing a common interface. This package is used by the protoc-gen-connect-dart protoc plugin for making Connect requests.

This package is published as ska_connect, because connect is too generic.

Using

This client depends on generated Dart protobuf code for the request and response types. You can get the latest precompiled binary for your system here and the Dart compiler here. The example proto file can be compiled with:

protoc --proto_path=./test/proto --dart_out=./test/rpc ./test/proto/greet.proto

Dependencies

In your pubspec.yaml specify:

http: ^0.13.0
protobuf: ^2.0.0

Making Unary Requests

Required packages:

import 'package:http/http.dart' as http;
import 'package:ska_connect/ska_connect.dart';
import './rpc/greet.pb.dart' as greet;
final client = HttpConnectClient('http://localhost', http.Client());

// response will contain a response or an error
final resp = await client.performRequest(
    '/greet.v1.GreetService/Greet',
    greet.GreetRequest(name: 'Chuck'),
    // decode function to generate the response type from a buffer
    (b) => greet.GreetResponse.fromBuffer(b));

if (resp.isError) {
  // The response was an error, response.error will not be null
  print(resp.error);
} else {
  // The call was successful
  print(resp.response!.greeting);
}

Running tests

dart pub get
dart test