-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
hello.rs
37 lines (28 loc) · 968 Bytes
/
hello.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![deny(warnings)]
extern crate hyper;
extern crate futures;
extern crate pretty_env_logger;
extern crate tokio;
use futures::Future;
use hyper::{Body, Response, Server};
use hyper::service::service_fn_ok;
static PHRASE: &'static [u8] = b"Hello World!";
fn main() {
pretty_env_logger::init();
let addr = ([127, 0, 0, 1], 3000).into();
// new_service is run for each connection, creating a 'service'
// to handle requests for that specific connection.
let new_service = || {
// This is the `Service` that will handle the connection.
// `service_fn_ok` is a helper to convert a function that
// returns a Response into a `Service`.
service_fn_ok(|_| {
Response::new(Body::from(PHRASE))
})
};
let server = Server::bind(&addr)
.serve(new_service)
.map_err(|e| eprintln!("server error: {}", e));
println!("Listening on http://{}", addr);
tokio::run(server);
}