mirror of
https://github.com/actix/actix-website
synced 2024-11-27 18:12:57 +01:00
24 lines
540 B
Rust
24 lines
540 B
Rust
// <path>
|
|
use actix_web::{get, web, App, HttpServer, Result};
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Deserialize)]
|
|
struct Info {
|
|
username: String,
|
|
}
|
|
|
|
// extract path info using serde
|
|
#[get("/{username}/index.html")] // <- define path parameters
|
|
async fn index(info: web::Path<Info>) -> Result<String> {
|
|
Ok(format!("Welcome {}!", info.username))
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| App::new().service(index))
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await
|
|
}
|
|
// </path>
|