2018-05-24 10:13:55 -07:00
|
|
|
// <path>
|
2020-09-12 16:21:54 +01:00
|
|
|
use actix_web::{get, web, App, HttpServer, 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
|
2020-09-12 16:21:54 +01:00
|
|
|
#[get("/{username}/index.html")] // <- define path parameters
|
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))
|
|
|
|
}
|
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-29 04:10:02 +09:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2020-09-12 16:21:54 +01:00
|
|
|
HttpServer::new(|| App::new().service(index))
|
2022-02-26 03:56:24 +00:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2020-09-12 16:21:54 +01:00
|
|
|
.run()
|
|
|
|
.await
|
2018-05-24 10:13:55 -07:00
|
|
|
}
|
|
|
|
// </path>
|