ash-rpc-cli-1.0.1 is not a library.
ash-rpc
A comprehensive, modular JSON-RPC 2.0 implementation for Rust with multiple transport layers and extra features.
Features
- Full implementation with requests, responses, notifications, and batch operations
- TCP, TCP streaming, HTTP via Axum, and Tower middleware
- Fluent API for constructing requests and responses
- Organize and dispatch JSON-RPC methods with automatic routing
- Generate OpenAPI/Swagger specifications from method definitions
- Efficient caching and optimized request handling
- Use only what you need with feature flags
- Support for context-aware method handlers
- CLI tool for generating boilerplate code
- Convenient macros for common response patterns
Packages
This workspace contains four packages:
ash-rpc-core
- Core JSON-RPC implementation with transport supportash-rpc-stateful
- Stateful JSON-RPC handlers with shared contextash-rpc-cli
- Code generation CLI toolexamples
- Comprehensive examples and demos
Quick Start
# Optional: for stateful handlers
Basic Usage
use *;
TCP Server
use ;
use Arc;
async
HTTP Server with Axum
use *;
use ;
use Arc;
async
Tower Middleware
use JsonRpcLayer;
use ;
use ;
let middleware = new
.layer
.service;
Stateful Handlers
use *;
use ;
let context = AppContext ;
let mut registry = new;
registry.register_stateful;
Documentation Generation
Generate OpenAPI/Swagger documentation from your JSON-RPC methods:
use *;
let mut registry = new;
registry.register_with_docs;
// Generate OpenAPI spec
let docs = registry.render_docs;
println!;
Examples
The examples/
directory contains comprehensive examples:
basic.rs
- Simple method registration and callingtcp_server.rs
- TCP server implementationaxum_server.rs
- HTTP server with Axumtower_http_simple.rs
- Tower middleware with HTTPtower_tcp_simple.rs
- Tower middleware with TCPcalculator_engine.rs
- Advanced calculator with macro usagestateful_server.rs
- Stateful context examplesdocs_demo.rs
- Documentation generationcaching_demo.rs
- Performance optimization with caching
Feature Flags
Configure the library with feature flags:
[]
= { = "0.1.0", = ["tcp", "tower", "docs"] }
Available features:
tcp
- TCP transport supporttcp-stream
- TCP streaming supporttower
- Tower middleware supportdocs
- Documentation generationmacros
- Convenience macros
CLI Tool
Generate boilerplate code with the CLI tool:
# Generate a new service
Performance
The library includes several performance optimizations:
- Efficient JSON parsing with serde
- Method dispatch caching for faster lookups
- Documentation caching to avoid regeneration
- Connection pooling for TCP streams
- Minimal allocations in hot paths
Architecture
ash-rpc-core/
├── types.rs # Core JSON-RPC types
├── builders.rs # Fluent builders for requests/responses
├── traits.rs # Handler and processor traits
├── registry.rs # Method registration and dispatch
├── transport.rs # TCP and streaming transports
├── middleware.rs # Tower middleware integration
├── macros.rs # Convenience macros
└── utils.rs # Documentation and utility functions
Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
cargo test
- Submit a pull request
License
- MIT License (LICENSE-MIT)