1
0
mirror of https://github.com/actix/actix-website synced 2025-03-11 18:52:58 +01:00

31 lines
719 B
Rust
Raw Normal View History

2019-06-20 02:04:22 -04:00
pub mod async_stream;
pub mod stream;
// <async-responder>
2019-06-28 13:31:30 -04:00
use actix_web::{Error, HttpResponse};
2019-06-20 02:04:22 -04:00
use futures::future::{ok, Future};
2019-06-15 16:37:08 -04:00
fn index() -> Box<dyn Future<Item = HttpResponse, Error = Error>> {
2019-06-20 02:04:22 -04:00
Box::new(ok::<_, Error>(
HttpResponse::Ok().content_type("text/html").body("Hello!"),
))
2019-06-15 16:37:08 -04:00
}
fn index2() -> Box<dyn Future<Item = &'static str, Error = Error>> {
2019-06-20 02:04:22 -04:00
Box::new(ok::<_, Error>("Welcome!"))
2019-06-15 16:37:08 -04:00
}
fn main() {
2019-06-28 13:31:30 -04:00
use actix_web::{web, App, HttpServer};
HttpServer::new(|| {
App::new()
.route("/async", web::to_async(index))
.route("/", web::to_async(index2))
})
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
2019-06-15 16:37:08 -04:00
}
2019-06-20 02:04:22 -04:00
// </async-responder>