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 types::*;pub use builders::*;pub use traits::*;pub use registry::*;
Modules§
- auth
- Authentication and authorization hooks
- builders
- Builder patterns for JSON-RPC types.
- logger
- Logging trait for ash-rpc-core
- macros
- Convenience macros for JSON-RPC response creation.
- registry
- Method registry for organizing and dispatching JSON-RPC methods.
- sanitization
- Optional error sanitization utilities
- 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
- 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_
success - Create a success response with a result value and optional ID
- rpc_try
- Convert Result types to JSON-RPC responses with error logging
- rpc_
validate - Handle common validation patterns