Skip to content

v0.6.0

Choose a tag to compare

@vkiryakov vkiryakov released this 16 Oct 17:07
· 25 commits to dev since this release
41add92

Zefir 0.6.0 adds rpc: typed calls between Zig services, on transports you can plug in.

rpc

zefir-rpc describes a service once, as a contract written in Zig, and the compiler checks the server and its clients against the same types. Calls travel as JSON over a transport: NATS in production, memory in tests, or one you write yourself.

  • An engine that runs handlers with limits, deadlines that travel into nested calls, cancellation, authentication, middleware on three levels and a graceful stop, the same way on every transport.
  • A contract, rpc.Server and rpc.Client; JSON and validation with zefir-validator on both sides; failures of a service come as values with stable codes.
  • Transports on vtables, a memory transport and a public conformance suite, so a transport can live in a package of its own: examples/rpc-custom-transport is one.
  • zefir-rpc-nats: request-reply over NATS, errors as in ADR-32, NATS micro discovery.
  • zefir-rpc-log: access logs on zefir-log, one record per call, never bodies or credentials.
  • rpc.testing.Server runs your handlers with everything around them in memory.

Not implemented yet: transports over HTTP (Connect) and TCP, TLS (zefir-nats speaks plain TCP, so run rpc over NATS only in a network you trust), streaming, codecs other than JSON, retries.

See the rpc guide and the rpc-nats guide: every chapter with a program the build compiles and runs, and its real output.

nats

  • Client.publishMessageTimeout, SubscribeOptions.timeout and Subscription.isDenied().
  • Breaking: Client.SubscribeError gains Timeout. An exhaustive switch on it without else needs a new branch; without .timeout the error never happens.
zig fetch --save git+https://github.com/vkiryakov/zefir#v0.6.0
const zefir = b.dependency("zefir", .{ .target = target, .optimize = optimize });
// in your module's .imports:
.{ .name = "rpc", .module = zefir.module("zefir-rpc") },
.{ .name = "rpc-nats", .module = zefir.module("zefir-rpc-nats") },

The NATS transport also needs zio; the rpc-nats guide's Installation shows how to add it.

Until 1.0, breaking changes may happen in any minor release.