axum-jrpc

Crates.ioaxum-jrpc
lib.rsaxum-jrpc
version0.7.1
sourcesrc
created_at2022-04-27 13:09:38.051156
updated_at2024-07-02 20:31:53.284887
descriptionA JSON-RPC extractor for Axum
homepagehttps://github.com/0xdeafbeef/axum-jrpc
repositoryhttps://github.com/0xdeafbeef/axum-jrpc
max_upload_size
id576044
size70,620
Vladimir (0xdeafbeef)

documentation

README

Json RPC extractor for axum

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

Crates.io Documentation

Commit count: 41

cargo fmt