简体   繁体   English

我如何解析包含特定单词的请求uri

[英]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.

相关问题 如何从隐式请求的JSON中解析出边界类型T的对象? - How can I parse an object of a bounded type T from JSON from an implicit request? 如何在喷涂路由中解析获取请求参数? - How can I parse out get request parameters in spray-routing? 哪个java类可以解析hadoop支持的文件系统uri? - which java class can parse hadoop supported file system uri? 我可以设置特定管道请求的超时和重试次数吗? - Can I set a timeout and number of retries on a specific pipeline request? 如何解析动态json响应并获取特定值并将其作为输入传递给下一个请求 - How to parse dynamic json reponse and get specific value and pass it as an input to next request 如何查看 MultipartForm 请求的内容? - How can I See the content of a MultipartForm request? 如何使用Scala在向量中找到单词数? - How can I find the word count in a vector using scala? 如何将现有单词从一列移到另一列? - How can I remove existing word from one column to another? 如何在 Play Framework 中解析 data[i][j] 类型的请求参数? - How do I parse a request parameter of type data[i][j] in Play Framework? 如何解析包含在Scala中始终具有更改名称的字段的json? - How to parse a json containing a field that always has a changed name in Scala?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM