Crate spirit_hyper[][src]

Spirit extension for Hyper servers.

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…).

Tokio runtime

This uses the spirit_tokio crate under the hood. Similar drawback with initializing a runtime applies here too (see the spirit_tokio docs for details).

Examples

use hyper::{Body, Request, Response};
use serde::Deserialize;
use spirit::{Empty, Pipeline, Spirit};
use spirit::prelude::*;
use spirit_hyper::{server_from_handler, BuildServer, HttpServer};

const DEFAULT_CONFIG: &str = r#"
[server]
port = 2234
"#;

#[derive(Default, Deserialize)]
struct Config {
    server: HttpServer,
}

impl Config {
    fn server(&self) -> HttpServer {
        self.server.clone()
    }
}

async fn request(_req: Request<Body>) -> Response<Body> {
    Response::new(Body::from("Hello world\n"))
}

fn main() {
    Spirit::<Empty, Config>::new()
        .config_defaults(DEFAULT_CONFIG)
        .with(
            // Let's build a http server as configured by the user
            Pipeline::new("listen")
                .extract_cfg(Config::server)
                // This is where we teach the server what it serves. It is the usual stuff from
                // hyper.
                .transform(BuildServer(server_from_handler(request)))
        )
        .run(|spirit| {
            Ok(())
        });
}

Further examples (with more flexible handling) are in the git repository.

Structs

Acceptor

A plumbing wrapper type.

Activate

A plumbing helper type.

BuildServer

A Transformation to turn a Builder into a Server.

HyperCfg

Configuration of Hyper HTTP servers.

HyperServer

A Fragment for hyper servers.

Enums

HttpMode

Configuration of the selected HTTP protocol version.

Traits

ServerBuilder

A trait abstracting the creation of servers.

Functions

server_from_handler

A simplified version of creating the ServerBuilder.

Type Definitions

HttpServer

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