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.
Each HttpTransport
instance is backed by exactly one Hyper
Client
and all HttpHandle
s created through the same
HttpTransport
also point to that same Client
instance.
By default Hyper Client
s 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 support is compiled if the "tls" feature is enabled (it is enabled by default).
When TLS support is compiled in the instances returned by
HttpTransport::new
and
HttpTransport::shared
support both plaintext http
and https over TLS, backed by the hyper_tls::HttpsConnector
connector.
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
:
```rust
extern crate jsonrpcclienthttp;
use jsonrpcclienthttp::HttpTransport;
jsonrpcclient!(pub struct FizzBuzzClient {
/// Returns the fizz-buzz string for the given number.
pub fn fizzbuzz(&mut self, number: u64) -> RpcRequest
fn main() { let transport = HttpTransport::new().unwrap(); let transporthandle = transport.handle("https://api.fizzbuzzexample.org/rpc/").unwrap(); let mut client = FizzBuzzClient::new(transporthandle); let result1 = client.fizzbuzz(3).call().unwrap(); let result2 = client.fizzbuzz(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