Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic PathMatcher from String

I have a test server that takes expectations at runtime and responds accordingly when the expectation is called. The expectations are stored in state. Here's the route:

val route: Route = ctx => {
  val routes = state.map { case (pathString, responses) =>
    get {
      path(pathString) {
         ...
      }
    }
  }
  concat(routes: _*)(ctx)
}

This approach works when the expected path does not have any slashes, e.g. foo.html. But when it has a fuller path, e.g. foo/bar.html, then the directive will not match.

How can I correctly convert the given path string into a PathMatcher?

I have tried pathString.split("/").foldLeft(Neutral)(_ / _) but this caused the simple case of foo.html to fail.

like image 215
Synesso Avatar asked Jul 30 '26 13:07

Synesso


1 Answers

PathMatchers.separateOnSlashes(String) is provided by the library and does what I need.

like image 80
Synesso Avatar answered Aug 02 '26 05:08

Synesso