v0.25.0
[v0.25.0] - 2025-04-24
A new breaking release which has been in the making for a while and the biggest change is that the
RpcServiceT trait has been changed to support both the client and server side:
pub trait RpcServiceT {
/// Response type for `RpcServiceT::call`.
type MethodResponse;
/// Response type for `RpcServiceT::notification`.
type NotificationResponse;
/// Response type for `RpcServiceT::batch`.
type BatchResponse;
/// Processes a single JSON-RPC call, which may be a subscription or regular call.
fn call<'a>(&self, request: Request<'a>) -> impl Future<Output = Self::MethodResponse> + Send + 'a;
/// Processes multiple JSON-RPC calls at once, similar to `RpcServiceT::call`.
///
/// This method wraps `RpcServiceT::call` and `RpcServiceT::notification`,
/// but the root RPC service does not inherently recognize custom implementations
/// of these methods.
///
/// As a result, if you have custom logic for individual calls or notifications,
/// you must duplicate that implementation in this method or no middleware will be applied
/// for calls inside the batch.
fn batch<'a>(&self, requests: Batch<'a>) -> impl Future<Output = Self::BatchResponse> + Send + 'a;
/// Similar to `RpcServiceT::call` but processes a JSON-RPC notification.
fn notification<'a>(&self, n: Notification<'a>) -> impl Future<Output = Self::NotificationResponse> + Send + 'a;
}
The reason for this change is to make it work for the client-side as well as make it easier to
implement performantly by relying on impl Future instead of requiring an associated type for the Future (which in many cases requires boxing).
The downside of this change is that one has to duplicate the logic in the batch and call method to achieve the same
functionality as before. Thus, call or notification is not being invoked in the batch method and one has to implement
them separately.
For example now it's possible to write middleware that counts the number of method calls as follows (both client and server):
#[derive(Clone)]
pub struct Counter<S> {
service: S,
count: Arc<AtomicUsize>,
role: &'static str,
}
impl<S> RpcServiceT for Counter<S>
where
S: RpcServiceT + Send + Sync + Clone + 'static,
{
type MethodResponse = S::MethodResponse;
type NotificationResponse = S::NotificationResponse;
type BatchResponse = S::BatchResponse;
fn call<'a>(&self, req: Request<'a>) -> impl Future<Output = Self::MethodResponse> + Send + 'a {
let count = self.count.clone();
let service = self.service.clone();
let role = self.role;
async move {
let rp = service.call(req).await;
count.fetch_add(1, Ordering::SeqCst);
println!("{role} processed calls={} on the connection", count.load(Ordering::SeqCst));
rp
}
}
fn batch<'a>(&self, batch: Batch<'a>) -> impl Future<Output = Self::BatchResponse> + Send + 'a {
let len = batch.len();
self.count.fetch_add(len, Ordering::SeqCst);
println!("{} processed calls={} on the connection", self.role, self.count.load(Ordering::SeqCst));
self.service.batch(batch)
}
fn notification<'a>(&self, n: Notification<'a>) -> impl Future<Output = Self::NotificationResponse> + Send + 'a {
self.service.notification(n)
}
}
In addition because this middleware is quite powerful it's possible to modify requests and specifically the request ID which should be avoided because it may break the response verification especially for the client-side. See https://github.com/paritytech/jsonrpsee/issues/1565 for further information.
There are also a couple of other changes see the detailed changelog below.
[Added]
- middleware: RpcServiceT distinct return types for notif, batch, call (#1564)
- middleware: add support for client-side (#1521)
- feat: add namespace_separator option for RPC methods (#1544)
- feat: impl Into for Infallible (#1542)
- client: add
request timeoutgetter (#1533) - server: add example how to close a connection from a rpc handler (method call or subscription) (#1488)
- server: add missing
ServerConfigBuilder::build(#1484)
[Fixed]
- chore(macros): fix typo in proc-macro example (#1482)
- chore(macros): fix typo in internal type name (#1507)
- http middleware: preserve the URI query in ProxyGetRequest::call (#1512)
- http middlware: send original error in ProxyGetRequest (#1516)
- docs: update comment for TOO_BIG_BATCH_RESPONSE_CODE error (#1531)
- fix
http request bodylog (#1540)
[Changed]
- unify usage of JSON via
Box<RawValue>(#1545) - server:
ServerConfigBuilder/ServerConfigreplacesServerBuilderduplicate setter methods (#1487) - server: make
ProxyGetRequestLayerhttp middleware support multiple path-method pairs (#1492) - server: propagate extensions in http response (#1514)
- server: add assert set_message_buffer_capacity (#1530)
- client: add #[derive(Clone)] for HttpClientBuilder (#1498)
- client: add Error::Closed for ws close (#1497)
- client: use native async fn in traits instead async_trait crate (#1551)
New Contributors
- @Pana made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1482
- @HaoranYi made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1507
- @king-11 made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1519
- @AlexZhenWang made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1531
- @emhane made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1533
- @hai-rise made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1540
- @YakupAltay made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1544
- @Hack666r made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1552
- @petryshkaCODE made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1553
- @mdqst made their first contribution in https://github.com/paritytech/jsonrpsee/pull/1556
Full Changelog: https://github.com/paritytech/jsonrpsee/compare/v0.24.9...v0.25.0