From c3c2286e3ac3c1c9ac6914cc430a9a20dd899721 Mon Sep 17 00:00:00 2001 From: Ali Shirvani Date: Sat, 24 Nov 2018 17:07:30 +0330 Subject: [PATCH] An other hello word example and update sample in README.md --- README.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3cb6f2308..e7205893d 100644 --- a/README.md +++ b/README.md @@ -14,20 +14,23 @@ Actix http ## Example ```rust +// see examples/framed_hello.rs for complete list of used crates. extern crate actix_http; use actix_http::{h1, Response, ServiceConfig}; fn main() { - Server::new() - .bind("app", addr, move || { - IntoFramed::new(|| h1::Codec::new(ServiceConfig::default())) // <- create h1 codec - .and_then(TakeItem::new().map_err(|_| ())) // <- read one request - .and_then(|(req, framed): (_, Framed<_, _>)| { // <- send response and close conn - framed - .send(h1::OutMessage::Response(Response::Ok().finish())) - }) - }) - .run(); + env::set_var("RUST_LOG", "framed_hello=info"); + env_logger::init(); + + Server::new().bind("framed_hello", "127.0.0.1:8080", || { + IntoFramed::new(|| h1::Codec::new(ServiceConfig::default())) // <- create h1 codec + .and_then(TakeItem::new().map_err(|_| ())) // <- read one request + .and_then(|(_req, _framed): (_, Framed<_, _>)| { // <- send response and close conn + SendResponse::send(_framed, Response::Ok().body("Hello world!")) + .map_err(|_| ()) + .map(|_| ()) + }) + }).unwrap().run(); } ```