1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-31 11:02:08 +01:00

An other hello word example and update sample in README.md

This commit is contained in:
Ali Shirvani 2018-11-24 17:07:30 +03:30
parent d5ca6e21e2
commit c3c2286e3a

View File

@ -14,20 +14,23 @@ Actix http
## Example ## Example
```rust ```rust
// see examples/framed_hello.rs for complete list of used crates.
extern crate actix_http; extern crate actix_http;
use actix_http::{h1, Response, ServiceConfig}; use actix_http::{h1, Response, ServiceConfig};
fn main() { fn main() {
Server::new() env::set_var("RUST_LOG", "framed_hello=info");
.bind("app", addr, move || { env_logger::init();
IntoFramed::new(|| h1::Codec::new(ServiceConfig::default())) // <- create h1 codec
.and_then(TakeItem::new().map_err(|_| ())) // <- read one request Server::new().bind("framed_hello", "127.0.0.1:8080", || {
.and_then(|(req, framed): (_, Framed<_, _>)| { // <- send response and close conn IntoFramed::new(|| h1::Codec::new(ServiceConfig::default())) // <- create h1 codec
framed .and_then(TakeItem::new().map_err(|_| ())) // <- read one request
.send(h1::OutMessage::Response(Response::Ok().finish())) .and_then(|(_req, _framed): (_, Framed<_, _>)| { // <- send response and close conn
}) SendResponse::send(_framed, Response::Ok().body("Hello world!"))
}) .map_err(|_| ())
.run(); .map(|_| ())
})
}).unwrap().run();
} }
``` ```