#json-rpc-client #json-rpc #hyper-client #rpc-client #http #client

jsonrpc-client-http

A transport implementation for jsonrpc-client-core based on Hyper and futures

7 releases (4 breaking)

Uses old Rust 2015

0.5.0 Jun 25, 2018
0.4.0 Jun 18, 2018
0.3.0 Mar 6, 2018
0.2.2 Oct 5, 2017
0.1.0 Jul 19, 2017

#427 in HTTP client

Download history 43/week @ 2024-03-17 38/week @ 2024-03-24 70/week @ 2024-03-31 35/week @ 2024-04-07 42/week @ 2024-04-14 48/week @ 2024-04-21 38/week @ 2024-04-28 36/week @ 2024-05-05 39/week @ 2024-05-12 40/week @ 2024-05-19 35/week @ 2024-05-26 43/week @ 2024-06-02 26/week @ 2024-06-09 46/week @ 2024-06-16 45/week @ 2024-06-23 4/week @ 2024-06-30

128 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

45KB
659 lines

jsonrpc-client-http

HTTP transport implementation for the JSON-RPC 2.0 clients generated by jsonrpc-client-core.

Uses the async Tokio based version of Hyper to implement a JSON-RPC 2.0 compliant HTTP transport.

Reusing connections

Each HttpTransport instance is backed by exactly one Hyper Client and all HttpHandles created through the same HttpTransport also point to that same Client instance.

By default Hyper Clients have keep-alive activated and open connections will be kept and reused if more requests are sent to the same destination before the keep-alive timeout is reached.

TLS / HTTPS

TLS support is compiled if the "tls" feature is enabled.

When TLS support is enabled the builder returned from HttpTransport::with_tls will produce a HttpTransport supporting both plaintext http and encrypted https over TLS, backed by the hyper_tls::HttpsConnector connector.

Examples

See the integration test in tests/localhost.rs for code that creates an actual HTTP server with jsonrpc_http_server, and sends requests to it with this crate.

Here is a small example of how to use this crate together with jsonrpc_core:

#[macro_use] extern crate jsonrpc_client_core;
extern crate jsonrpc_client_http;

use jsonrpc_client_http::HttpTransport;

jsonrpc_client!(pub struct FizzBuzzClient {
    /// Returns the fizz-buzz string for the given number.
    pub fn fizz_buzz(&mut self, number: u64) -> RpcRequest<String>;
});

fn main() {
    let transport = HttpTransport::new().standalone().unwrap();
    let transport_handle = transport.handle("https://api.fizzbuzzexample.org/rpc/").unwrap();
    let mut client = FizzBuzzClient::new(transport_handle);
    let result1 = client.fizz_buzz(3).call().unwrap();
    let result2 = client.fizz_buzz(4).call().unwrap();
    let result3 = client.fizz_buzz(5).call().unwrap();

    // Should print "fizz 4 buzz" if the server implemented the service correctly
    println!("{} {} {}", result1, result2, result3);
}

License: MIT/Apache-2.0

Dependencies

~11–21MB
~301K SLoC