Crates.io | axum-jrpc |
lib.rs | axum-jrpc |
version | 0.7.1 |
source | src |
created_at | 2022-04-27 13:09:38.051156 |
updated_at | 2024-07-02 20:31:53.284887 |
description | A JSON-RPC extractor for Axum |
homepage | https://github.com/0xdeafbeef/axum-jrpc |
repository | https://github.com/0xdeafbeef/axum-jrpc |
max_upload_size | |
id | 576044 |
size | 70,620 |
JsonRpcExtractor
parses JSON-RPC requests and validates it's correctness.
use axum_jrpc::{JrpcResult, JsonRpcExtractor, JsonRpcResponse};
fn router(req: JsonRpcExtractor) -> JrpcResult {
let req_id = req.get_answer_id()?;
let method = req.method();
let response =
match method {
"add" => {
let params: [i32; 2] = req.parse_params()?;
JsonRpcResponse::success(req_id, params[0] + params[1]);
}
m => req.method_not_found(m)
};
Ok(response)
}