Skip to content

Commit e202b3d

Browse files
Create main.rst
1 parent 42ea97b commit e202b3d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/main.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
2+
3+
#[get("/")]
4+
async fn hello() -> impl Responder {
5+
HttpResponse::Ok().body("Hello world!")
6+
}
7+
8+
#[post("/echo")]
9+
async fn echo(req_body: String) -> impl Responder {
10+
HttpResponse::Ok().body(req_body)
11+
}
12+
13+
async fn manual_hello() -> impl Responder {
14+
HttpResponse::Ok().body("Hey there!")
15+
}
16+
17+
#[actix_web::main]
18+
async fn main() -> std::io::Result<()> {
19+
HttpServer::new(|| {
20+
App::new()
21+
.service(hello)
22+
.service(echo)
23+
.route("/hey", web::get().to(manual_hello))
24+
})
25+
.bind(("127.0.0.1", 8080))?
26+
.run()
27+
.await
28+
}

0 commit comments

Comments
 (0)