Expand description
§ash-rpc-core
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
- 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
- Macro support - Convenient macros for common response patterns
§Quick Start
use ash_rpc_core::*;
use serde_json::Value;
// Create a method registry
let registry = MethodRegistry::new()
.register("ping", |_params, id| {
rpc_success!("pong", id)
})
.register("add", |params, id| {
if let Some(params) = params {
let nums: Vec<i32> = serde_json::from_value(params).unwrap();
if nums.len() == 2 {
rpc_success!(nums[0] + nums[1], id)
} else {
rpc_error!(error_codes::INVALID_PARAMS, "Expected 2 numbers", id)
}
} else {
rpc_error!(error_codes::INVALID_PARAMS, "Parameters required", id)
}
});
// Call a method
let response = registry.call("ping", None, Some(Value::Number(serde_json::Number::from(1))));
Re-exports§
Modules§
- builders
- Builder patterns for JSON-RPC types.
- macros
- Convenience macros for JSON-RPC response creation.
- registry
- Method registry for organizing and dispatching JSON-RPC methods.
- traits
- Core traits for JSON-RPC handlers and processors.
- transport
- types
- Core JSON-RPC 2.0 types and data structures.
- utils
- Utility functions for JSON-RPC documentation generation.
Macros§
- 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_
internal_ error - rpc_
invalid_ params - Common error response shortcuts using predefined error codes
- rpc_
method_ not_ found - rpc_
notification - Create a JSON-RPC notification
- rpc_
parse_ error - rpc_
request - Create a JSON-RPC request
- rpc_
success - Create a success response with a result value and optional ID