One call surface (id_effect_rpc)
Since 0.12 id_effect has one first-party way for services, browsers and other nodes to call each
other: RPC through id_effect_rpc (ADR 0014).
A procedure is written once — an effect from a typed input to a typed output with typed errors —
and the same contract is callable over HTTP, WebSocket, server-sent events, HTTP/3, WebTransport
and the process mesh, from Rust, from the generated TypeScript client and from other nodes.
REST + OpenAPI over typed routes stays the recommended style for public, third-party APIs; the RPC contract exports OpenAPI 3.1 and AsyncAPI so a public consumer never needs the RPC client. GraphQL is a non-goal.
Procedures
A service is a set of procedures, each with a tag ("<Service>.<procedure>"), a kind, input and
output schemas, a typed error union, and an access decision:
| Kind | Shape | HTTP mapping |
|---|---|---|
| query | one input, one output; retry-safe | GET /rpc/{tag}?input= with ETag/304, or POST /rpc |
| mutation | one input, one output; replayable by Idempotency-Key | POST /rpc |
| server stream | one input, a stream of outputs | NDJSON response, SSE |
| client stream | a stream of inputs, one output | chunked NDJSON request |
| two-way stream | both directions, credit backpressure, resume | WebSocket, WebTransport |
| subscription | a resumable stream from a cursor | SSE, WebSocket |
Every procedure is either public() or guard(g); one with neither does not compile (ADR 0014
rule C1, the same rule as typed routes). An unknown tag answers 404 Problem Details. Typed errors
are part of the contract ({"_tag": "NotFound", …}); a defect reaches the client as
InternalError { id } with only the correlation id.
#![allow(unused)] fn main() { use std::sync::Arc; use id_effect::{DynEnv, schema, succeed}; use id_effect_rpc::{Procedure, RpcGroup, RpcServer}; let mut group = RpcGroup::new(); group.register( Procedure::query("Greeter.greet").public(), Arc::new(schema::string::<()>()), Arc::new(schema::string::<()>()), &["message"], |name, _env| succeed(format!("Hello, {name}!")), ); let contract = group.service_contract("Greeter", 1); // what clients are generated from let app: axum::Router = RpcServer::new(group).mount_default().with_state(DynEnv::new()); let _ = (contract, app); }
RpcServer mounts POST /rpc as a declared route of id_effect_axum::route::Router, so it lives
behind the same deny-by-default layer as every other route; each procedure's own guards run on the
request head before its input is decoded.
The contract
Service::contract() (generated by #[rpc::service]) and RpcGroup::service_contract produce an
id_effect_rpc::contract::Contract: services, versions, procedures, kinds, access decisions and the
JSON Schemas of inputs, outputs and errors. It is checked in as rpc.contract.json and kept current
by a golden test (contract::assert_snapshot, UPDATE_GOLDEN=1 rewrites it). id-effect rpc gen ts
and id-effect rpc check read that file without compiling anything; versions are served side by
side, and rpc check fails on a breaking change to a published version.
Wire, codecs and limits
JSON is the default encoding; postcard is negotiated per connection
(application/vnd.id-effect.rpc+postcard, WebSocket subprotocol idrpc.postcard.v1) and always
used node to node. A batch is a JSON array of calls (at most 50 calls and 1 MiB), stream frames are
at most 64 KiB, and every stream, connection and resume buffer has a finite limit. The envelope,
frame, cursor and session formats are fixed in id_effect_rpc::wire.
In this part
- Procedures, errors and cancellation
- Batching
- Encodings
- The service macro
- WebSocket and SSE in the host
- RPC transports
- Two-way streams and resume
- Subscriptions
- Channels and presence
- Contracts, OpenAPI 3.1 and AsyncAPI
- The TypeScript client
- Checking a contract
Each section lands with the 0.12 change that implements it.
See also
- API boundaries — correlation ids, error envelopes, versioning
- RPC boundaries — choosing a wire stack
- Typed routes and validation — the access rule RPC shares