14 releases (8 breaking)
0.9.0 | Apr 3, 2021 |
---|---|
0.8.1 | Jan 10, 2021 |
0.7.1 | Oct 28, 2020 |
0.6.0 | Oct 19, 2019 |
0.2.0 | Oct 15, 2018 |
#5 in #spirit
54 downloads per month
Used in spirit
435KB
5.5K
SLoC
Spirit-hyper
Several helpers to easily integrate hyper with configuration managed by the spirit system.
See the docs and the examples.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
[Spirit][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.
Dependencies
~11–23MB
~285K SLoC