Crate jsonrpc_client_http[][src]

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

Re-exports

pub extern crate error_chain;

Modules

header

Headers container, and common header fields.

Structs

DefaultClient

Default Client creator that defaults to creating a standard Client with just hyper::Client::new(handle).

Error

The Error type.

Handle

A non-sendable handle to an event loop, useful for manufacturing instances of LoopData.

HttpHandle

A handle to a HttpTransport. This implements jsonrpc_client_core::Transport and can be used as the transport for a RPC client generated by the jsonrpc_client! macro.

HttpTransport

The main struct of the HTTP transport implementation for jsonrpc_client_core.

HttpTransportBuilder

Builder type for HttpTransport.

Enums

ErrorKind

The kind of an error.

Traits

ClientCreator

Trait for types able to produce Hyper Clients for use in HttpTransport.

ResultExt

Additional methods for Result, for easy interaction with this crate.

Type Definitions

Result

Convenient wrapper around std::Result.