2
#[get("/starts-with/{other_url}")]
async fn t1(other_url: web::Path<String>) -> impl Responder {
    other_url.to_string()
}

This handler works for /starts-with/a, but it doesn't work for /starts-with/a/b.

How can I create a route which works with an arbitrary number of slashes?

Max Block
  • 1,134
  • 3
  • 16
  • 23
  • I would try `Path` from `std::path`. So `other_url: web::Path`. I have no idea whether it will work though. (Don't know anything about actix-web and didn't look it up) – skywalker Jun 21 '22 at 12:10

1 Answers1

4

Based on this similar question and actix doc you could use the regex pattern match like

#[get("/starts-with/{other_url:.*}")]
async fn t1(other_url: web::Path<String>) -> impl Responder {
    other_url.to_string()
}
➜ curl http://127.0.0.1:8081/starts-with/x/y
Path("x/y")%
➜ curl http://127.0.0.1:8081/starts-with/x
Path("x")%
➜ curl http://127.0.0.1:8081/starts-with/x/y/z
Path("x/y/z")%

but this will require further parsing of the string.

Ashok
  • 66
  • 5