1
0
mirror of https://github.com/actix/actix-website synced 2025-03-16 05:02:45 +01:00

33 lines
696 B
Rust
Raw Normal View History

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
}
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-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!")
}
2020-09-12 16:21:54 +01:00
// </handlers>
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<()> {
HttpServer::new(|| {
App::new()
2020-09-12 16:21:54 +01:00
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
2020-09-12 16:21:54 +01:00
.bind("127.0.0.1:8080")?
.run()
2019-12-29 01:33:19 +09:00
.await
2018-05-23 23:25:51 +02:00
}
// </main>