mirror of
https://github.com/actix/actix-website
synced 2025-02-02 12:19:04 +01:00
Update main-example
This commit is contained in:
parent
9da187a36c
commit
94c8c843b1
@ -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,20 +1,20 @@
|
|||||||
// <main-example>
|
// <main-example>
|
||||||
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
use actix_web::{web, App, HttpRequest, HttpServer, Responder};
|
||||||
|
|
||||||
fn greet(req: HttpRequest) -> impl Responder {
|
async fn greet(req: HttpRequest) -> impl Responder {
|
||||||
let name = req.match_info().get("name").unwrap_or("World");
|
let name = req.match_info().get("name").unwrap_or("World");
|
||||||
format!("Hello {}!", &name)
|
format!("Hello {}!", &name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.route("/", web::get().to(greet))
|
.route("/", web::get().to(greet))
|
||||||
.route("/{name}", web::get().to(greet))
|
.route("/{name}", web::get().to(greet))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
// </main-example>
|
// </main-example>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user