Rory
Rory

Reputation: 838

How to match String using pathPrefix/rawPathPrefix in Akka HTTP?

This works:

rawPathPrefix("Ad(" ~ LongNumber ~ ")") { id =>

id is now a Long, but this doesn't work:

rawPathPrefix("Ad(" ~ String ~ ")") { id =>

id is now a RequestContext, not a String?

Upvotes: 1

Views: 921

Answers (2)

Jeffrey Chung
Jeffrey Chung

Reputation: 19517

One approach is to use a regex pattern that captures one or more characters between Ad( and ) in the path prefix:

pathPrefix("""Ad\((.+)\)""".r) { id =>
  ...
}

For example, id is the string "12-34b" for a request sent to:

http://host:port/Ad(12-34b)

Upvotes: 2

Shankar Shastri
Shankar Shastri

Reputation: 1154

You need to use Segment.

path("hello"/Segment) 

Check this: https://doc.akka.io/docs/akka-http/current/routing-dsl/path-matchers.html#examples

Upvotes: -1

Related Questions