Files
hyper/examples/hello.rs
Sean McArthur 3cd48b45fb feat(lib): replace types with those from http crate
BREAKING CHANGE: `Method`, `Request`, `Response`, `StatusCode`,
  `Version`, and `Uri` have been replaced with types from the `http`
  crate. The `hyper::header` module is gone for now.

  Removed `Client::get`, since it needed to construct a `Request<B>`
  with an empty body. Just use `Client::request` instead.

  Removed `compat` cargo feature, and `compat` related API.
2018-03-19 11:43:47 -07:00

26 lines
653 B
Rust

#![deny(warnings)]
extern crate hyper;
extern crate futures;
extern crate pretty_env_logger;
use hyper::{Body, Response};
use hyper::server::{Http, const_service, service_fn};
static PHRASE: &'static [u8] = b"Hello World!";
fn main() {
pretty_env_logger::init();
let addr = ([127, 0, 0, 1], 3000).into();
let new_service = const_service(service_fn(|_| {
Ok(Response::new(Body::from(PHRASE)))
}));
let server = Http::new()
.sleep_on_errors(true)
.bind(&addr, new_service)
.unwrap();
println!("Listening on http://{} with 1 thread.", server.local_addr().unwrap());
server.run().unwrap();
}