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:

KindShapeHTTP mapping
queryone input, one output; retry-safeGET /rpc/{tag}?input= with ETag/304, or POST /rpc
mutationone input, one output; replayable by Idempotency-KeyPOST /rpc
server streamone input, a stream of outputsNDJSON response, SSE
client streama stream of inputs, one outputchunked NDJSON request
two-way streamboth directions, credit backpressure, resumeWebSocket, WebTransport
subscriptiona resumable stream from a cursorSSE, 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

  1. Procedures, errors and cancellation
  2. Batching
  3. Encodings
  4. The service macro
  5. WebSocket and SSE in the host
  6. RPC transports
  7. Two-way streams and resume
  8. Subscriptions
  9. Channels and presence
  10. Contracts, OpenAPI 3.1 and AsyncAPI
  11. The TypeScript client
  12. Checking a contract

Each section lands with the 0.12 change that implements it.

See also