Skip to main content

Crate ndjson_rpc

Crate ndjson_rpc 

Source
Expand description

Line-delimited JSON-RPC framing ({ id, verb, args }{ id, result | error | event | end }) with two interchangeable transports — a Unix-domain-socket server / client for local control planes, and an HTTP/1.1 server / client that streams the same frames as Transfer-Encoding: chunked NDJSON.

See the README for the gap this fills (daemon ↔ CLI control planes that everyone re-implements).

Re-exports§

pub use client::MgmtClientError;
pub use client::UnixMgmtClient;
pub use http_client::HttpMgmtClient;
pub use http_server::HttpServerConfig;
pub use http_server::HttpServerError;
pub use http_server::spawn_http_server;
pub use protocol::EndMarker;
pub use protocol::Request;
pub use protocol::Response;
pub use protocol::ResponseOutcome;
pub use protocol::WireError;
pub use protocol::WireErrorKind;
pub use protocol::encode_line;
pub use server::DispatchOutcome;
pub use server::EventStream;
pub use server::Handler;
pub use server::spawn_unix_server;

Modules§

client
Typed Unix-socket client. Same frame shapes as crate::server. One Unix-socket connection per call: the API stays a simple call(verb, args) -> result, and a future multiplexed transport can be slotted in without changing the call shape.
http_client
HTTP-over-TCP management client. Mirrors crate::UnixMgmtClient but talks to crate::http_server over hyper::client::conn::http1.
http_server
HTTP-over-TCP transport for the same NDJSON frame shapes the Unix socket crate::server speaks.
protocol
Wire format: line-delimited JSON over a duplex byte stream. Each request is one JSON object on one line; each response is one JSON object on one line; lines end with \n. No length prefix — the framing is the newline. NDJSON keeps tools such as nc -U piped through jq usable for ad-hoc poking. The same frame shapes ride the HTTP-over-TCP transport (NDJSON over chunked encoding).
server
Unix-socket accept loop + per-connection line-delimited JSON dispatch to verb handlers. The HTTP-over-TCP transport (crate::http_server) speaks the same frame shapes, so dispatch logic is shared.