Expand description
The RpcServer — Axum-based JSON-RPC server with lifecycle
integration for dig_service::ShutdownToken.
§Responsibilities
- Build an Axum
Routerwith:POST /— JSON-RPC dispatch.GET /healthz— liveness.GET /metrics— Prometheus (behind themetricsfeature, wired by the binary).
- Attach the middleware stack: request-id, panic-catch, audit, rate-limit, allow-list.
- Drive
axum-serverwith TLS configured perRpcServerMode. - Exit
servewhen the suppliedShutdownTokenfires.
§v0.1 scope
The v0.1 server implements the full JSON-RPC dispatch pipeline and
includes per-request rate limiting. Full mTLS client-cert extraction is
wired via rustls’s WebPkiClientVerifier at TLS-handshake time, but
binaries that want to resolve the authenticated cert to a Role
in middleware should plug in a pluggable extractor (v0.2 enhancement).
§Minimal example
use std::sync::Arc;
use dig_rpc::{RpcServer, RpcServerMode, MethodRegistry, MethodMeta, RateBucket};
use dig_rpc::role::Role;
let api: Arc<MyApi> = Arc::new(MyApi);
let registry = MethodRegistry::new();
registry.register(MethodMeta::read("healthz", Role::Explorer, RateBucket::ReadLight));
let server = RpcServer::new(api, registry, RpcServerMode::public_plaintext("127.0.0.1:9447".parse().unwrap()));
let shutdown = dig_service::ShutdownToken::new();
match server.serve(shutdown).await {
Ok(()) => unreachable!(),
Err(e) => return e,
}Structs§
- RpcServer
- The JSON-RPC server itself.
Enums§
- RpcServer
Mode - Server deployment mode.