pub struct JsonRpcDispatcher { /* private fields */ }Expand description
JSON-RPC 2.0 request dispatcher.
Routes incoming JSON-RPC requests to the underlying RequestHandler.
Optionally applies CORS headers to all responses.
Implementations§
Source§impl JsonRpcDispatcher
impl JsonRpcDispatcher
Sourcepub const fn new(handler: Arc<RequestHandler>) -> JsonRpcDispatcher
pub const fn new(handler: Arc<RequestHandler>) -> JsonRpcDispatcher
Creates a new dispatcher wrapping the given handler.
Sourcepub fn with_cors(self, cors: CorsConfig) -> JsonRpcDispatcher
pub fn with_cors(self, cors: CorsConfig) -> JsonRpcDispatcher
Sets CORS configuration for this dispatcher.
When set, all responses will include CORS headers, and OPTIONS preflight
requests will be handled automatically.
Sourcepub async fn dispatch(
&self,
req: Request<Incoming>,
) -> Response<BoxBody<Bytes, Infallible>>
pub async fn dispatch( &self, req: Request<Incoming>, ) -> Response<BoxBody<Bytes, Infallible>>
Dispatches a JSON-RPC request and returns an HTTP response.
For SendStreamingMessage and SubscribeToTask, the response uses
SSE (text/event-stream). All other methods return JSON.
JSON-RPC errors are always returned as HTTP 200 with an error body.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JsonRpcDispatcher
impl !RefUnwindSafe for JsonRpcDispatcher
impl Send for JsonRpcDispatcher
impl Sync for JsonRpcDispatcher
impl Unpin for JsonRpcDispatcher
impl UnsafeUnpin for JsonRpcDispatcher
impl !UnwindSafe for JsonRpcDispatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more