mirror of
https://github.com/actix/actix-website
synced 2025-01-22 16:15:56 +01:00
Update request-routing
This commit is contained in:
parent
cc2a7a0645
commit
b0e8a8d51d
@ -4,4 +4,5 @@ version = "1.0.0"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "1.0"
|
actix-web = "2.0"
|
||||||
|
actix-rt = "1.0"
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
// <request-routing>
|
// <request-routing>
|
||||||
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||||
|
|
||||||
fn index(_req: HttpRequest) -> impl Responder {
|
async fn index(_req: HttpRequest) -> impl Responder {
|
||||||
"Hello from the index page."
|
"Hello from the index page."
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hello(path: web::Path<String>) -> impl Responder {
|
async fn hello(path: web::Path<String>) -> impl Responder {
|
||||||
format!("Hello {}!", &path)
|
format!("Hello {}!", &path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.service(web::resource("/").to(index))
|
.service(web::resource("/").to(index))
|
||||||
.service(web::resource("/{name}").to(hello))
|
.service(web::resource("/{name}").to(hello))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
// </request-routing>
|
// </request-routing>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user