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"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
||||
actix-web = "2.0"
|
||||
actix-rt = "1.0"
|
||||
|
@ -1,23 +1,23 @@
|
||||
// <request-routing>
|
||||
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."
|
||||
}
|
||||
|
||||
fn hello(path: web::Path<String>) -> impl Responder {
|
||||
async fn hello(path: web::Path<String>) -> impl Responder {
|
||||
format!("Hello {}!", &path)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(web::resource("/").to(index))
|
||||
.service(web::resource("/{name}").to(hello))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
.unwrap();
|
||||
.await
|
||||
}
|
||||
// </request-routing>
|
||||
|
Loading…
x
Reference in New Issue
Block a user