0
votes

this path directive of akka http matches /hello

lazy val userRoutes: Route = cors() {
  path(Segment) { p => ... }

how can I match both /hello and /hello/ (optional end slash)?

After reading the doc https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/path-directives/index.html#pathdirectives I've tried as follows, but it does not compile:

lazy val userRoutes: Route = cors() {
  rawPathPrefix(Slash ~ Segment ~ pathEndOrSingleSlash) { p => ... }
1

1 Answers

0
votes

Akka-Http provides path directives using which you can solve the following.

val route =
  pathPrefix("hello") {
    pathEndOrSingleSlash {
      complete("/hello")
    }
  }

https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/path-directives/pathEndOrSingleSlash.html