1
0
mirror of https://github.com/actix/actix-website synced 2024-11-28 10:32:38 +01:00
actix-website/examples/async-handlers/src/main.rs
2019-06-15 16:37:08 -04:00

26 lines
705 B
Rust

mod async_stream;
mod stream;
// <main>
use actix_web::{App, AsyncResponder, Error, HttpRequest, HttpResponse};
use futures::future::{result, Future};
fn index(_req: &HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
result(Ok(HttpResponse::Ok()
.content_type("text/html")
.body(format!("Hello!"))))
.responder()
}
fn index2(_req: &HttpRequest) -> Box<Future<Item = &'static str, Error = Error>> {
result(Ok("Welcome!")).responder()
}
fn main() {
App::new()
.resource("/async", |r| r.route().a(index))
.resource("/", |r| r.route().a(index2))
// .resource("/", |r| r.route().f(async_stream::index))
.finish();
}
// </main>