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 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

Attribute Macros§

async_trait