mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
improve path docs
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
// <path-one>
|
||||
use actix_web::{get, web, Result};
|
||||
use actix_web::{get, web, App, HttpServer, Result};
|
||||
|
||||
/// extract path info from "/users/{user_id}/{friend}" url
|
||||
/// {user_id} - deserializes to a u32
|
||||
@ -12,8 +12,6 @@ async fn index(path: web::Path<(u32, String)>) -> Result<String> {
|
||||
|
||||
#[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()
|
||||
|
@ -1,12 +1,12 @@
|
||||
use actix_web::{get, HttpRequest, Result};
|
||||
|
||||
// <path-three>
|
||||
#[get("/users/{userid}/{friend}")] // <- define path parameters
|
||||
#[get("/users/{user_id}/{friend}")] // <- define path parameters
|
||||
async fn index(req: HttpRequest) -> Result<String> {
|
||||
let name: String = req.match_info().get("friend").unwrap().parse().unwrap();
|
||||
let userid: i32 = req.match_info().query("userid").parse().unwrap();
|
||||
let userid: i32 = req.match_info().query("user_id").parse().unwrap();
|
||||
|
||||
Ok(format!("Welcome {}, userid {}!", name, userid))
|
||||
Ok(format!("Welcome {}, user_id {}!", name, userid))
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
|
Reference in New Issue
Block a user