13

Is possible to pass more than one parameter into axtic_web route ?

// srv.rs (frag.)

HttpServer::new(|| {
  App::new()
    .route(
      "/api/ext/{name}/set/config/{id}",
      web::get().to(api::router::setExtConfig),
    )
})
.start();
// router.rs (frag.)

pub fn setExtConfig(
    name: web::Path<String>,
    id: web::Path<String>,
    _req: HttpRequest,
) -> HttpResponse {
  println!("{} {}", name, id);
  HttpResponse::Ok()
      .content_type("text/html")
      .body("OK")
}

For routes with one param everything is ok, but for this example i see only message in the browser: wrong number of parameters: 2 expected 1, and the response stauts code is 404.

I realy need to pass more parameters (from one to three or four)...

Piotr Płaczek
  • 530
  • 1
  • 8
  • 20

1 Answers1

11

That is a perfect fit for tuple:

pub fn setExtConfig(
    param: web::Path<(String, String)>,
    _req: HttpRequest,
) -> HttpResponse {
    println!("{} {}", param.0, param.1);
    HttpResponse::Ok().content_type("text/html").body("OK")
}
edwardw
  • 12,652
  • 3
  • 40
  • 51