Routing doesn't work for two non-overlapping routes #2332
-
Expected BehaviorI expect the following code two produce two distinct routes: use std::net::SocketAddr;
use actix_web::{web, App, HttpServer, Responder};
#[actix_web::main]
async fn main() {
let address: SocketAddr = "127.0.0.1:8080".parse().unwrap();
let server = HttpServer::new(move || {
App::new().service(
web::scope("/api/v0").service(
web::scope("/collection")
// FIXME: this routing doesn't work.
// NOTE: switching these two routes doesn't work.
.route("/{uuid}", web::get().to(by_uuid))
.route("/user/{user_name}/{unqualified_id}", web::get().to(by_id)),
),
)
})
.bind(address)
.unwrap();
println!("http://{}", address);
server.run().await.unwrap();
}
pub async fn by_uuid(uuid: web::Path<String>) -> impl Responder {
format!("by UUID: {}", uuid)
}
pub async fn by_id(
user_name: web::Path<String>,
unqualified_id: web::Path<String>,
) -> impl Responder {
format!("by id: {}/{}", user_name, unqualified_id)
} Current BehaviorHowever
It seem Actix is routing the request to the uuid route and hitting an error. Steps to Reproduce (for bugs)
Your Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
So the issue is just closed without any comment? |
Beta Was this translation helpful? Give feedback.
-
Routes are matches in the order they are declared, so you'll always match the {uuid} route in this case. from
|
Beta Was this translation helpful? Give feedback.
Routes are matches in the order they are declared, so you'll always match the {uuid} route in this case.
from
web::resource
docs: