2020-09-12 16:21:54 +01:00
|
|
|
// <handlers>
|
|
|
|
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
|
2018-05-23 23:25:51 +02:00
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[get("/")]
|
|
|
|
async fn hello() -> 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
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[post("/echo")]
|
|
|
|
async fn echo(req_body: String) -> impl Responder {
|
|
|
|
HttpResponse::Ok().body(req_body)
|
2019-06-19 18:00:31 -04:00
|
|
|
}
|
2019-06-12 04:56:59 -04:00
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
async fn manual_hello() -> impl Responder {
|
2019-08-06 01:30:50 +02:00
|
|
|
HttpResponse::Ok().body("Hey there!")
|
2019-08-05 18:32:00 +02:00
|
|
|
}
|
2020-09-12 16:21:54 +01:00
|
|
|
// </handlers>
|
2019-08-05 18:32:00 +02:00
|
|
|
|
2018-05-23 23:25:51 +02:00
|
|
|
// <main>
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-29 01:33:19 +09:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-19 18:00:31 -04:00
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new()
|
2020-09-12 16:21:54 +01:00
|
|
|
.service(hello)
|
|
|
|
.service(echo)
|
|
|
|
.route("/hey", web::get().to(manual_hello))
|
2019-06-19 18:00:31 -04:00
|
|
|
})
|
2020-09-12 16:21:54 +01:00
|
|
|
.bind("127.0.0.1:8080")?
|
2019-06-19 18:00:31 -04:00
|
|
|
.run()
|
2019-12-29 01:33:19 +09:00
|
|
|
.await
|
2018-05-23 23:25:51 +02:00
|
|
|
}
|
|
|
|
// </main>
|