Skip to main content

Crate ash_rpc

Crate ash_rpc 

Source
Expand description

§ash-rpc

A comprehensive JSON-RPC 2.0 implementation with transport support.

§Features

  • Complete JSON-RPC 2.0 support - Request, response, notification, and batch handling
  • Multiple transports - TCP, TCP streaming, HTTP via Axum, and Tower middleware
  • Stateful handlers - Context-aware method handlers with shared application state
  • Type-safe builders - Fluent API for constructing requests and responses
  • Method registry - Organize and dispatch JSON-RPC methods
  • Auto-documentation - Generate OpenAPI/Swagger specs from method definitions
  • Code generation - CLI tool for generating boilerplate implementations
  • Macro support - Convenient macros for common response patterns

§Quick Start

use ash_rpc::*;

struct PingMethod;

#[async_trait::async_trait]
impl JsonRPCMethod for PingMethod {
    fn method_name(&self) -> &'static str { "ping" }
     
    async fn call(
        &self,
        _params: Option<serde_json::Value>,
        id: Option<RequestId>,
    ) -> Response {
        rpc_success!("pong", id)
    }
}

// Create a method registry
let registry = MethodRegistry::new(register_methods![PingMethod]);

Re-exports§

pub use transports::SecurityConfig;
pub use transports::TcpServer;
pub use transports::TcpServerBuilder;
pub use transports::TcpStreamClient;
pub use transports::TcpStreamClientBuilder;
pub use transports::TcpStreamServer;
pub use transports::TcpStreamServerBuilder;
pub use transports::TcpStreamTlsClient;
pub use transports::TcpStreamTlsServer;
pub use transports::TcpStreamTlsServerBuilder;
pub use transports::TlsConfig;
pub use transports::axum;
pub use observability::ObservabilityBuilder;
pub use observability::ObservableProcessor;
pub use observability::prometheus as obs_prometheus;
pub use observability::tracing as obs_tracing;
pub use tokio;
pub use tower;
pub use prometheus;
pub use opentelemetry;
pub use opentelemetry_otlp;
pub use opentelemetry_sdk;
pub use types::*;
pub use builders::*;
pub use traits::*;
pub use registry::*;
pub use stateful::*;
pub use streaming::*;
pub use shutdown::*;
pub use audit_logging::*;
pub use healthcheck::*;
pub use middleware::*;

Modules§

audit_logging
Security audit logging for ash-rpc
auth
Authentication and authorization hooks
builders
Builder patterns for JSON-RPC types.
healthcheck
Health check JSON-RPC method implementation
logger
Logging trait for ash-rpc-core
macros
Convenience macros for JSON-RPC response creation.
middleware
Tower middleware for JSON-RPC services
observability
Observability features for ash-rpc
registry
Method registry for organizing and dispatching JSON-RPC methods.
sanitization
Optional error sanitization utilities
shutdown
Graceful shutdown support for JSON-RPC servers.
stateful
Stateful JSON-RPC Handlers
streaming
Streaming and subscription support for JSON-RPC.
traits
Core traits for JSON-RPC handlers and processors.
transports
Transport layer implementations for JSON-RPC servers.
types
Core JSON-RPC 2.0 types and data structures.

Macros§

dispatch_call
Macro to generate a dispatch function with compile-time method matching This replaces runtime iteration with a compile-time generated match statement
observable_setup
Simplifies observability stack initialization with a declarative syntax
register_methods
Macro to generate method dispatch match arms for registered JsonRPCMethod implementations
rpc_call_request
Create a simple JSON-RPC client call
rpc_error
Create an error response with code, message, and optional ID
rpc_error_obj
Create a JSON-RPC error object (not a response)
rpc_error_with_data
Create an error response with code, message, additional data and optional ID
rpc_extract
Extract result from JSON-RPC response
rpc_internal_error
rpc_invalid_params
Common error response shortcuts using predefined error codes
rpc_method
Define a simple JSON-RPC method with automatic trait implementation
rpc_method_not_found
rpc_notification
Create a JSON-RPC notification
rpc_params
Validate and extract parameters with automatic error responses
rpc_parse_error
rpc_registry_with_methods
Build a registry with multiple method instances
rpc_request
Create a JSON-RPC request
rpc_stateful_builder
Create a stateful processor with builder pattern
rpc_stateful_processor
Create a stateful JSON-RPC processor
rpc_stateful_registry
Create a stateful method registry
rpc_success
Create a success response with a result value and optional ID
rpc_tcp_server
Create and run a TCP JSON-RPC server
rpc_tcp_stream_client
Create a TCP streaming JSON-RPC client
rpc_tcp_stream_server
Create and run a TCP streaming JSON-RPC server
rpc_try
Convert Result types to JSON-RPC responses with error logging
rpc_validate
Handle common validation patterns
shutdown_hook
Macro to register a shutdown hook
stream_event
Helper macro for creating stream events

Attribute Macros§

async_trait