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

21 lines
639 B
Rust
Raw Normal View History

2019-06-16 23:17:17 -04:00
// <path-one>
2022-04-07 15:54:55 +01:00
use actix_web::{get, web, App, HttpServer, Result};
2019-06-16 23:17:17 -04:00
2020-09-12 16:21:54 +01:00
/// extract path info from "/users/{user_id}/{friend}" url
/// {user_id} - deserializes to a u32
2019-06-16 23:17:17 -04:00
/// {friend} - deserializes to a String
2020-09-12 16:21:54 +01:00
#[get("/users/{user_id}/{friend}")] // <- define path parameters
2022-02-26 03:56:24 +00:00
async fn index(path: web::Path<(u32, String)>) -> Result<String> {
let (user_id, friend) = path.into_inner();
2020-09-12 16:21:54 +01:00
Ok(format!("Welcome {}, user_id {}!", friend, user_id))
2019-06-16 23:17:17 -04:00
}
2020-09-12 16:21:54 +01:00
#[actix_web::main]
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
2019-06-16 23:17:17 -04:00
}
// </path-one>