Crate spirit_hyper
source ·Expand description
Spirit helper for Hyper
This allows having Hyper servers auto-spawned from configuration. It is possible to put them on top of arbitrary stream-style IO objects (TcpStream, UdsStream, these wrapped in SSL…).
Examples
extern crate hyper;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate spirit;
extern crate spirit_hyper;
extern crate spirit_tokio;
use hyper::{Body, Request, Response};
use spirit::{Empty, Spirit};
use spirit_hyper::HttpServer;
const DEFAULT_CONFIG: &str = r#"
[server]
port = 1234
"#;
#[derive(Default, Deserialize)]
struct Config {
server: HttpServer,
}
impl Config {
fn server(&self) -> HttpServer {
self.server.clone()
}
}
fn request(_req: Request<Body>) -> Response<Body> {
Response::new(Body::from("Hello world\n"))
}
fn main() {
Spirit::<Empty, Config>::new()
.config_defaults(DEFAULT_CONFIG)
.config_helper(Config::server, spirit_hyper::server_ok(request), "server")
.run(|spirit| {
Ok(())
});
}
Further examples are in the git repository.
Structs
A
ResourceConfig
for hyper servers.Traits
Factory for
MakeService
implementations.Functions
Creates a
ResourceConsumer
from a ConfiguredMakeService
.Like
server
, but taking a closure to answer request directly.Creates a hyper
ResourceConfig
for a closure that returns the Response
directly.Creates a hyper
ResourceConfig
for a closure that returns a future of Response
.Type Definitions
A type alias for http (plain TCP) hyper server.