[英]How Can I parse a request uri containing specific word
I am trying to handle a request containing word "filter". 我正在尝试处理包含单词“ filter”的请求。 For the time being, I am using the url as http://localhost:9997/filter= ....
目前,我使用的网址为http:// localhost:9997 / filter = ...。
and parsing by using pathPrefix(fiter) 和使用pathPrefix(fiter)进行解析
But url will change and becomes like http://localhost:9997/something../filter= 但是url会改变,变成像http:// localhost:9997 / something ../ filter =
So here I can't take pathPrefix(). 所以在这里我不能采用pathPrefix()。 How can I handle this kind of path in routing so that any url containing "filter" keyword it can handle.
如何处理路由中的此类路径,以便包含“ filter”关键字的所有网址都可以处理。 I am very much new to akka spray.
我对Akka Spray非常陌生。 Please let me know about your opinions.
请让我知道您的意见。 Thanks in advance
提前致谢
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”(可能足以满足您的需求)
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. 但是如果filter的两端都不匹配:“ filter / blah / blah”或“ balh / blah / filter”,但是您可以通过匹配前缀和后缀来解决。 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 看看http://spray.io/documentation/1.2.3/spray-routing/predefined-directives-alphabetically/#predefined-directives
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.