The crate http-service
provides the necessary types and traits to implement your own HTTP Server. It uses hyper
for the lower level TCP abstraction.
You can use the workspace member http-service-hyper
to run your HTTP Server.
http_service_hyper::run(HTTP_SERVICE, ADDRESS);
await
ed via http_service_hyper::serve(HTTP_SERVICE, ADDRESS);
This crate uses the latest Futures preview, and therefore needs to be run on Rust Nightly.
Cargo.toml
```toml [dependencies] http-service = "0.3.0" futures-preview = "0.3.0-alpha.17"
[dependencies.http-service-hyper] version = "0.3.0" ```
main.rs
```rust,no_run
use futures::future::{self, BoxFuture, FutureExt}; use http_service::{HttpService, Response}; use std::net::{IpAddr, Ipv4Addr, SocketAddr};
struct Server {
message: Vec
impl Server {
fn create(message: Vec
pub fn run(s: Server) {
let a = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8088);
http_service_hyper::run(s, a);
}
}
impl HttpService for Server {
type Connection = ();
type ConnectionFuture = future::Ready
fn connect(&self) -> Self::ConnectionFuture {
future::ok(())
}
fn respond(&self, _conn: &mut (), _req: http_service::Request) -> Self::ResponseFuture {
let message = self.message.clone();
async move { Ok(Response::new(http_service::Body::from(message))) }.boxed()
}
}
fn main() { let s = Server::create(String::from("Hello, World").into_bytes()); Server::run(s); } ```
Want to join us? Check out our The "Contributing" section of the guide and take a look at some of these issues:
The http-service project adheres to the Contributor Covenant Code of Conduct. This describes the minimum behavior expected from all contributors.
MIT OR Apache-2.0