pub async fn call(
router: &Router,
method: &str,
params: Value,
ctx: &ConnectionContext,
) -> Result<Value, RpcError>Expand description
Call a registered JSON-RPC method from a REST handler, in-process.
Why: the single seam every future REST resource handler goes through, so
a REST route and its JSON-RPC method twin are provably the same code
path — never two handwritten implementations of the same business logic
(see module docs).
What: synthesizes a Request { jsonrpc: "2.0", id: Some(0), method, params } — the id is a fixed synthetic value because a REST caller
never observes it; dispatch never suppresses a response as long as
id is Some(_) (see Router::dispatch’s notification rule) — calls
router.dispatch(req, ctx), and unwraps the Response envelope: Ok
when result is set, Err reconstructing the RpcError from
Response::error otherwise. If dispatch ever returned a Response
with neither result nor error set — a Router::dispatch bug, not a
caller-triggerable condition, and provably unreachable through this
bridge since call always sets a non-None id, so dispatch never
returns Response::suppressed() — this falls back to Ok(Value::Null)
rather than panicking (no unwrap/expect in library code). That would
surface as a silently-wrong 200 response, not a panic.
Test: call_success_returns_handler_result, call_error_returns_rpc_error.