Struct jsonrpsee_http_server::HttpServerBuilder[][src]

pub struct HttpServerBuilder<M = ()> { /* fields omitted */ }
Expand description

Builder to create JSON-RPC HTTP server.

Implementations

Create a default server builder.

Add a middleware to the builder Middleware.

use std::time::Instant;

use jsonrpsee_core::middleware::Middleware;
use jsonrpsee_http_server::HttpServerBuilder;

#[derive(Clone)]
struct MyMiddleware;

impl Middleware for MyMiddleware {
    type Instant = Instant;

    fn on_request(&self) -> Instant {
        Instant::now()
    }

    fn on_result(&self, name: &str, success: bool, started_at: Instant) {
        println!("Call to '{}' took {:?}", name, started_at.elapsed());
    }
}

let builder = HttpServerBuilder::new().set_middleware(MyMiddleware);

Sets the maximum size of a request body in bytes (default is 10 MiB).

Sets access control settings.

Enables or disables HTTP keep-alive.

Default is true.

Register a new resource kind. Errors if label is already registered, or if the number of registered resources on this server instance would exceed 8.

See the module documentation for resurce_limiting for details.

Configure a custom tokio::runtime::Handle to run the server on.

Default: tokio::spawn

Finalizes the configuration of the server.

#[tokio::main]
async fn main() {
  let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
  let occupied_addr = listener.local_addr().unwrap();
  let addrs: &[std::net::SocketAddr] = &[
      occupied_addr,
      "127.0.0.1:0".parse().unwrap(),
  ];
  assert!(jsonrpsee_http_server::HttpServerBuilder::default().build(occupied_addr).is_err());
  assert!(jsonrpsee_http_server::HttpServerBuilder::default().build(addrs).is_ok());
}

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more