# 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](https://github.com/Industrial/id_effect/blob/main/docs/adrs/0014-one-call-surface.md)).
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](./ch29-01-typed-routes.md) 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**:
| 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.
```rust
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](./ch33-01-procedures.md)
2. [Batching](./ch33-02-batching.md)
3. [Encodings](./ch33-03-encodings.md)
4. [The service macro](./ch33-04-service-macro.md)
5. [WebSocket and SSE in the host](./ch33-05-websocket-sse.md)
6. [RPC transports](./ch33-06-rpc-transports.md)
7. [Two-way streams and resume](./ch33-07-two-way-streams.md)
8. [Subscriptions](./ch33-08-subscriptions.md)
9. [Channels and presence](./ch33-09-channels-presence.md)
10. [Contracts, OpenAPI 3.1 and AsyncAPI](./ch33-10-contracts.md)
11. [The TypeScript client](./ch33-11-typescript-client.md)
12. [Checking a contract](./ch33-12-contract-check.md)
Each section lands with the 0.12 change that implements it.
## See also
- [API boundaries](./ch29-00-api-boundaries.md) — correlation ids, error envelopes, versioning
- [RPC boundaries](../part2/ch07-12-rpc-boundaries.md) — choosing a wire stack
- [Typed routes and validation](./ch29-01-typed-routes.md) — the access rule RPC shares