-
I'm trying to write a route that supports #[get("/ref/{name}")]
pub async fn list_actions(
req: HttpRequest,
config: Data<Config>,
name: web::Path<String>
) -> Result<HttpResponse, Error> {
/// Example data.
}
#[get("/ref/{name}/{uuid}")]
pub async fn update_to_action(
req: HttpRequest,
config: Data<Config>,
name: web::Path<String>,
uuid: web::Path<String>,
) -> Result<HttpResponse, Error> {
/// Example data.
}
#[actix_web::main]
async fn main() -> Result<()> {
let server = HttpServer::new(move || {
let config_file = config_file.clone();
App::new()
.wrap(Logger::default())
.service(
web::scope("/api")
.service(list_actions)
.service(update_to_action),
)
.wrap(DefaultHeaders::new().add(("Example-App", APP_VERSION)))
});
Ok(())
} However, in my tests either I've been unable to get this working as expect. Either I get 404 when I attempt to call a path that matches _ Mike D. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I did review #2874 but that is only 0 or 1 parameters. I attempted something similar: #[get("/ref/{name}/{uuid}")]
pub async fn update_to_action(
req: HttpRequest,
config: Data<Config>,
data: Path<(String, Option<String>)>,
) -> Result<HttpResponse, Error> {
/// Data
} but that didn't seem to help. _ Mike D. |
Beta Was this translation helpful? Give feedback.
-
The only mistake you made in the OP was declaring multiple Path parameters in the This will try to extract one path param twice: name: web::Path<String>,
uuid: web::Path<String>, This, using a tuple type, will extract two path params. params: web::Path<(String, String)>, See the full solution here: https://www.rustexplorer.com/b/cfykzk |
Beta Was this translation helpful? Give feedback.
The only mistake you made in the OP was declaring multiple Path parameters in the
update_to_action
handler.This will try to extract one path param twice:
This, using a tuple type, will extract two path params.
See the full solution here: https://www.rustexplorer.com/b/cfykzk
(Uses a slightly nicer type from actix-web-lab that can be destructured, too.)