1
0
mirror of https://github.com/actix/actix-website synced 2025-03-11 10:42:58 +01:00

30 lines
598 B
Rust
Raw Normal View History

2018-05-24 10:13:55 -07:00
// <path>
2019-06-28 13:31:30 -04:00
use actix_web::{web, Result};
2019-06-16 20:19:25 -04:00
use serde::Deserialize;
2018-05-24 10:13:55 -07:00
#[derive(Deserialize)]
struct Info {
username: String,
}
// extract path info using serde
2019-12-29 04:10:02 +09:00
async fn index(info: web::Path<Info>) -> Result<String> {
2018-05-24 10:13:55 -07:00
Ok(format!("Welcome {}!", info.username))
}
2019-12-29 04:10:02 +09:00
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
2019-06-28 13:31:30 -04:00
use actix_web::{App, HttpServer};
2019-06-25 18:20:36 -04:00
HttpServer::new(|| {
App::new().route(
"/{username}/index.html", // <- define path parameters
web::get().to(index),
)
})
2019-12-29 04:10:02 +09:00
.bind("127.0.0.1:8088")?
2019-06-25 18:20:36 -04:00
.run()
2019-12-29 04:10:02 +09:00
.await
2018-05-24 10:13:55 -07:00
}
// </path>