2018-05-23 23:25:51 +02:00
|
|
|
// <setup>
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
2018-05-23 23:25:51 +02:00
|
|
|
|
2019-06-19 18:00:31 -04:00
|
|
|
fn index() -> impl Responder {
|
2019-06-12 04:51:45 -04:00
|
|
|
HttpResponse::Ok().body("Hello world!")
|
2018-05-23 23:25:51 +02:00
|
|
|
}
|
2019-06-19 18:00:31 -04:00
|
|
|
|
2019-06-28 13:31:30 -04:00
|
|
|
fn index2() -> impl Responder {
|
2019-06-19 18:00:31 -04:00
|
|
|
HttpResponse::Ok().body("Hello world again!")
|
|
|
|
}
|
2018-05-23 23:25:51 +02:00
|
|
|
// </setup>
|
2019-06-12 04:56:59 -04:00
|
|
|
|
2019-08-06 01:30:50 +02:00
|
|
|
// <macro-attributes>
|
2019-08-05 18:32:00 +02:00
|
|
|
use actix_web::get;
|
|
|
|
|
2019-08-06 01:30:50 +02:00
|
|
|
#[get("/hello")]
|
2019-08-05 18:32:00 +02:00
|
|
|
fn index3() -> impl Responder {
|
2019-08-06 01:30:50 +02:00
|
|
|
HttpResponse::Ok().body("Hey there!")
|
2019-08-05 18:32:00 +02:00
|
|
|
}
|
2019-08-06 01:30:50 +02:00
|
|
|
// </macro-attributes>
|
2019-08-05 18:32:00 +02:00
|
|
|
|
2018-05-23 23:25:51 +02:00
|
|
|
// <main>
|
|
|
|
fn main() {
|
2019-06-19 18:00:31 -04:00
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new()
|
|
|
|
.route("/", web::get().to(index))
|
|
|
|
.route("/again", web::get().to(index2))
|
|
|
|
})
|
|
|
|
.bind("127.0.0.1:8088")
|
|
|
|
.unwrap()
|
|
|
|
.run()
|
|
|
|
.unwrap();
|
2018-05-23 23:25:51 +02:00
|
|
|
}
|
|
|
|
// </main>
|