January 2019
Intermediate to advanced
520 pages
14h 32m
English
The Builder struct provides methods to tweak the parameters of the server created. For example, hyper's server supports both HTTP1 and HTTP2. You can use a builder value to choose either one protocol or both. In the following example, we're using builder to attach a service for handling incoming HTTP requests using the serve method:
let server = builder.serve(|| { service_fn_ok(|_| { Response::new(Body::from("Almost microservice...")) })});
Here, we're using the builder instance to attach a function that generates a Service instance. This function implements the hyper::service::NewService trait. The generated item then has to implement the hyper::service::Service trait. A service in a hyper crate is a function ...
Read now
Unlock full access