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.
Also serves the agent card at GET /.well-known/agent.json so that
JSON-RPC servers can participate in agent card discovery (spec §8.3).
Implementations§
Source§impl JsonRpcDispatcher
impl JsonRpcDispatcher
Sourcepub fn new(handler: Arc<RequestHandler>) -> JsonRpcDispatcher
pub fn new(handler: Arc<RequestHandler>) -> JsonRpcDispatcher
Creates a new dispatcher wrapping the given handler with default configuration.
Sourcepub fn with_config(
handler: Arc<RequestHandler>,
config: DispatchConfig,
) -> JsonRpcDispatcher
pub fn with_config( handler: Arc<RequestHandler>, config: DispatchConfig, ) -> JsonRpcDispatcher
Creates a new dispatcher with the given configuration.
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§
Source§impl Debug for JsonRpcDispatcher
impl Debug for JsonRpcDispatcher
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request