A path extractor of routing pattern for Play framework.
Play framework doesn't provide any way to acquire correspondence(s) of path placeholder and the value (as of version 2.6.13).
This library provides the function by PathVariablesExtractor
.
For example, the routing definition is /foo/:bar/:buz
and the path of actual request is /foo/Bar/BUZ
, then this library's method returns:
Map[String, String](
"bar" -> "Bar",
"buz" -> "BUZ",
)
Example of Play framework 2.6.x:
import play.api.mvc.RequestHeader
import play.api.routing.Router
def handle(requestHeader: RequestHeader) {
val placeholder2value = PathVariablesExtractor.extract(
requestHeader.attrs(Router.Attrs.HandlerDef).path,
requestHeader.path
)
// do something
}
Original discussion and solution: playframework/playframework#3378
moznion ([email protected])
Apache License 2.0