[][src]Crate spirit_hyper

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

HyperServer

A ResourceConfig for hyper servers.

Traits

ConfiguredMakeService

Factory for MakeService implementations.

Functions

server

Creates a ResourceConsumer from a ConfiguredMakeService.

server_configured

Like server, but taking a closure to answer request directly.

server_ok

Creates a hyper ResourceConfig for a closure that returns the Response directly.

server_simple

Creates a hyper ResourceConfig for a closure that returns a future of Response.

Type Definitions

HttpServer

A type alias for http (plain TCP) hyper server.