Hyper is a fast HTTP implementation written in and for Rust.
It is a low-level typesafe abstraction over raw HTTP, providing an elegant layer over "stringly-typed" HTTP.
Hyper offers both an HTTP client and server which can be used to drive complex web applications written entirely in Rust.
extern crate hyper;
use hyper::header::{ContentLength, ContentType};
use hyper::server::{Http, Response, const_service, service_fn};
static TEXT: &'static str = "Hello, World!";
fn run() -> Result<(), hyper::Error> {
let addr = ([127, 0, 0, 1], 3000).into();
let hello = const_service(service_fn(|_req|{
Ok(Response::<hyper::Body>::new()
.with_header(ContentLength(TEXT.len() as u64))
.with_header(ContentType::plaintext())
.with_body(TEXT))
}));
let server = Http::new().bind(&addr, hello)?;
server.run()
}
# fn main() {}