Crate jsonlrpc

Source
Expand description

A JSON-RPC 2.0 library that streams JSON objects in JSON Lines format.

§Example

use std::net::TcpStream;
use jsonlrpc::{RpcClient, RequestId, RequestObject, ResponseObject, JsonRpcVersion};

// Connect to a JSON-RPC server.
let server_addr = /* ... */
let socket = TcpStream::connect(server_addr).expect("failed to connect to server");
let mut client = RpcClient::new(socket);

// Send a request to the server.
let request = RequestObject {
    jsonrpc: JsonRpcVersion::V2,
    id: Some(RequestId::Number(1)),
    method: "foo".to_string(),
    params: None,
};
let response = client.call(&request).expect("failed to RPC call");

// Check the response.
let Some(ResponseObject::Ok { result, id, .. }) = response else {
    panic!("expected ok response, got notification or err response")
};
assert_eq!(id, RequestId::Number(1));

Structs§

ErrorCode
Error code.
ErrorObject
Error object.
JsonlStream
JSONL stream.
RequestObject
Default representation for a request object.
RpcClient
JSON-RPC client.

Enums§

JsonRpcVersion
JSON-RPC version.
MaybeBatch
Single or batch object.
RequestId
Request ID.
RequestParams
Request parameters.
ResponseObject
Default representation for a response object.