repe-rs
Rust implementation of the REPE RPC protocol with JSON and BEVE body support.
Features
- REPE header and message types with correct little-endian wire encoding.
- Streaming and zero-copy I/O (
MessageView,write_message_streaming) for large bodies. - JSON and BEVE bodies via
structio: one declaration serves both formats, and there is no document model, no derive, and no proc macro in the dependency graph. - Sync and async (tokio) clients and servers, with multiplexed in-flight requests, per-call timeouts, batching, and notify support.
- Dynamic
Registryrouting: a flat table of functions resolved by JSON Pointer. FleetAPIs for multi-node TCP and UDP fanout.- Optional REST gateway (
RestGateway) fronting aRegistryover HTTP/1.1 and HTTP/2, withETagrevalidation and JSON/BEVE negotiation. - Optional WebSocket transport, including a wasm browser client and server-pushed notify subscriptions.
- Optional
streammodule for backpressure-controlled bulk transfers with reconnect-resume. - Optional
repeCLI for talking to any REPE server over TCP or WebSocket.
Installation
Add to your Cargo.toml:
[]
= "13"
Or run cargo add repe.
Quick Start
A body is a type you declare. One structio::object! gives it both formats:
use ;
object!;
let msg = builder
.id
.query_str
.query_format
.body_json
.build;
let bytes = msg.to_vec;
let parsed = from_slice?;
assert_eq!;
assert_eq!;
assert!;
# Ok::
Replace body_json with body_beve to encode the same value as BEVE; the declaration is unchanged and everything else is identical.
object! is a macro_rules! macro, so declaring a type costs no proc macro and no build-time dependency. It also works on a type you do not own.
Server and Client
A minimal TCP server with one route, plus a client call:
use ;
;
object!;
object!;
let router = new.with_typed;
let server = new;
let listener = server.listen?;
let addr = listener.local_addr?;
spawn;
let client = connect?;
let pong: Pong = client.call_typed_json?;
assert!;
# Ok::
Every route names the type it takes and the type it returns. A request body is read straight into the handler's parameter and the return value is written straight into the response frame, with no intermediate document either way.
The async (tokio) variant uses AsyncServer and AsyncClient and exposes the same shape. See the Server guide for routers, typed handlers, middleware, struct registration, and peer-aware handlers, and the Client guide for the full client surface (typed and BEVE helpers, multiplexing, timeouts, batches, notifies, error handling).
Bulk numeric arrays
When a request and response are whole contiguous numeric arrays (f32, f64, integer widths), Router::with_typed_slice and Client::call_typed_slice (also AsyncClient::call_typed_slice) carry them on BEVE's typed-slice fast path: one bulk copy each way rather than a per-element walk. The wire bytes are identical to an ordinary Vec<T> body, so a with_typed_slice route and a with_typed / call_typed_beve peer interoperate freely.
use ;
let router = new
.;
let server = new;
let listener = server.listen?;
let addr = listener.local_addr?;
spawn;
let client = connect?;
let out: = client.call_typed_slice?;
assert_eq!;
# Ok::
For the request decode, Router::with_typed_slice_ref goes one step further and hands the handler a &[T] borrowed straight out of the receive buffer, with no allocation or element copy, when the client sends the aligned wire form via call_typed_slice_aligned:
use ;
let router = new
.;
let server = new;
let listener = server.listen?;
let addr = listener.local_addr?;
spawn;
let client = connect?;
let out: = client.call_typed_slice_aligned?;
assert_eq!;
# Ok::
A with_typed_slice_ref route is a drop-in superset of with_typed_slice: it still accepts the regular call_typed_slice clients (bulk-copying those), and falls back to a bulk copy whenever a borrow isn't possible, so correctness never depends on the alignment landing.
Feature Flags
| Flag | Effect |
|---|---|
rest |
RestGateway: a REST facade over a Registry, served on HTTP/1.1 and HTTP/2. |
plugin |
#[repe::plugin]: export a Router as a C-ABI plugin a REPE host loads. |
plugin-host |
plugin::host::Plugin: load and drive a plugin, including a C++ one. |
websocket |
Native WebSocketClient, WebSocketServer, and proxy_connection. |
websocket-wasm |
Browser WasmClient on wasm32-unknown-unknown. |
fleet-udp |
UDP fanout via UniUdpFleet. |
value-stream |
Streaming value transfer (SVS), with an optional Zstandard codec (pure Rust, no C toolchain). |
parking-lot |
Lockable impls for parking_lot::Mutex / RwLock. |
cli |
Builds the repe command-line client (pulls in clap and websocket). |
fleet-udp, value-stream, rest, plugin, and plugin-host are native-only: on wasm32-unknown-unknown their modules and their non-portable dependencies both compile away, so enabling any of them there is inert rather than a build failure. That matters for a workspace hoisting one shared feature set across a native server and a browser client, since Cargo features are additive and the wasm member cannot subtract one.
Documentation
Full documentation is hosted at repe-org.github.io/repe-rs.
- Server, routers, and handlers
- Client APIs
- Registry (dynamic routing)
- Fleet (multi-node control)
- WebSocket transport
- Streaming with backpressure
- Command-line client
- Wire format and JSON Pointer helpers
Examples
cargo run --example json_roundtrip
cargo run --example server
cargo run --example client
cargo run --example registry_server
cargo run --example registry_roundtrip
cargo run --example async_server
cargo run --example async_client
cargo run --example typed_numeric_body
Testing
Run cargo test to execute unit and integration tests. The crate denies warnings and includes async tests, so a recent tokio is required. Integration tests cover sync and async server/client calls, unknown routes, handler error mapping, ID mismatches, and timeouts.
License
MIT, see LICENSE.