1
0
mirror of https://github.com/actix/actix-website synced 2025-03-19 22:27:46 +01:00
2022-02-26 03:56:24 +00:00

29 lines
658 B
Rust

// <multi>
use actix_web::{get, web};
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
username: String,
}
#[get("/users/{user_id}/{friend}")] // <- define path parameters
async fn index(path: web::Path<(u32, String)>, query: web::Query<Info>) -> String {
let (user_id, friend) = path.into_inner();
format!(
"Welcome {}, friend {}, user_id {}!",
query.username, 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
}
// </multi>