mirror of
https://github.com/actix/actix-website
synced 2025-03-10 18:32:40 +01:00
22 lines
635 B
Rust
22 lines
635 B
Rust
// <path-one>
|
|
use actix_web::{get, web, Result};
|
|
|
|
/// extract path info from "/users/{user_id}/{friend}" url
|
|
/// {user_id} - deserializes to a u32
|
|
/// {friend} - deserializes to a String
|
|
#[get("/users/{user_id}/{friend}")] // <- define path parameters
|
|
async fn index(web::Path((user_id, friend)): web::Path<(u32, String)>) -> Result<String> {
|
|
Ok(format!("Welcome {}, user_id {}!", friend, user_id))
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
use actix_web::{App, HttpServer};
|
|
|
|
HttpServer::new(|| App::new().service(index))
|
|
.bind("127.0.0.1:8080")?
|
|
.run()
|
|
.await
|
|
}
|
|
// </path-one>
|