user1548787
user1548787

Reputation: 111

How Can I parse a request uri containing specific word

I am trying to handle a request containing word "filter". For the time being, I am using the url as http://localhost:9997/filter=....

and parsing by using pathPrefix(fiter)

But url will change and becomes like http://localhost:9997/something../filter=

So here I can't take pathPrefix(). How can I handle this kind of path in routing so that any url containing "filter" keyword it can handle. I am very much new to akka spray. Please let me know about your opinions. Thanks in advance

Upvotes: 0

Views: 173

Answers (1)

GClaramunt
GClaramunt

Reputation: 3158

If the string you want to match will always be at the end you can use "pathSuffix" (it might be enough for what you want)

pathSuffix("filter") { ... }

But if it can be anywhere in the path, is not that straighforward. One way is using segments:

path( Segment / "filter" / Segment ){ (prefix, postfix) => {...} }

But it doesn't match if filter is at either end: "filter/blah/blah" nor "balh/blah/filter", but you can work around by matching with prefix and suffix. I suppose there's a better way, maybe with a custom directive.

Take a look at http://spray.io/documentation/1.2.3/spray-routing/predefined-directives-alphabetically/#predefined-directives

Upvotes: 0

Related Questions