# json rpc JSON-RPC 2.0 server implementation in Rust # Example [full example](examples/hyper.rs) ```rust #[json_rpc] fn greet(name: String) -> Result { Ok(format!("Hello {}", name)) } struct System; #[json_rpc] impl System { fn time() -> Result { SystemTime::now().duration_since(UNIX_EPOCH).map(|v| v.as_secs()).map_err(|_| json_rpc_v2::Error::server_error()) } async fn issue() -> Result { read_to_string("/etc/issue").await.map_err(|_| json_rpc_v2::Error::server_error()) } } #[tokio::main] async fn main() -> Result<(), Box> { let mut registry = Registry::new(); registry.register_method("greet", greet); registry.register::(); let _ = registry.call(br#"{"jsonrpc":"2.0","method":"greet","params":["foo"],"id":1}"#).await; let _ = registry.call(br#"{"jsonrpc":"2.0","method":"system.time","params":[],"id":1}"#).await; let _ = registry.call(br#"{"jsonrpc":"2.0","method":"system.issue","params":[],"id":1}"#).await; Ok(()) } ```