vania_grpc 1.0.0 copy "vania_grpc: ^1.0.0" to clipboard
vania_grpc: ^1.0.0 copied to clipboard

Production-ready gRPC server and client integration for Vania.

Vania gRPC #

Run a gRPC server right beside your Vania HTTP server.

vania_grpc adds gRPC to a Vania app. gRPC is a fast, contract-first RPC protocol built on Protocol Buffers — great for service-to-service calls and low-latency APIs. This package lets you register your gRPC services with a provider and have them start automatically at boot, on their own port, alongside your regular HTTP server. One app, two protocols.

Install #

dependencies:
  vania_grpc: ^1.0.0

Register your services:

final providers = <ServiceProvider>[
  GrpcServiceProvider(
    services: [GreeterService()],
    config: GrpcConfig(
      host: env('GRPC_HOST', '0.0.0.0'),
      port: env<int>('GRPC_PORT', 50051),
      autoStart: true,
    ),
  ),
];

autoStart: true brings the gRPC server up when the app boots.

Define a service #

Services are standard grpc Service classes. Register each method and delegate to your own logic:

import 'package:vania_grpc/vania_grpc.dart';

class GreeterService extends Service {
  GreeterService() {
    $addMethod(ServiceMethod<HelloRequest, HelloResponse>(
      'SayHello', sayHello, false, false,
      HelloRequest.fromBuffer,
      (r) => r.writeToBuffer(),
    ));
  }

  @override
  String get $name => 'greeter.Greeter';

  Future<HelloResponse> sayHello(ServiceCall call, Future<HelloRequest> request) async {
    final req = await request;
    return HelloResponse(message: 'Hello, ${req.name}!');
  }
}

In a real project you generate the message classes from a .proto file with protoc; the service wiring stays the same.

Call it #

grpcurl -plaintext -d '{"name":"Vania"}' \
  localhost:50051 greeter.Greeter/SayHello

Good to know #

  • The gRPC server runs on its own port (GRPC_PORT, default 50051) next to your HTTP app.
  • Supports unary and streaming methods — set the streaming flags on ServiceMethod.
  • Keep your business rules in plain functions and let the service method be a thin wrapper; it stays easy to test.

License #

MIT

0
likes
160
points
77
downloads

Documentation

Documentation
API reference

Publisher

verified publishervdart.dev

Weekly Downloads

Production-ready gRPC server and client integration for Vania.

Homepage
Repository (GitHub)
View/report issues

Topics

#server #backend #grpc #rpc #vania

License

MIT (license)

Dependencies

grpc, meta, protobuf, vania

More

Packages that depend on vania_grpc