Scala-具有查询字符串解析器和Builder DSL的URL [英] Scala - URL with Query String Parser and Builder DSL
问题描述
在Scala中,如何通过编程方式构建带有查询字符串参数的URL?
In Scala how do I build up a URL with query string parameters programmatically?
我又如何将包含带有查询字符串参数的URL的String
解析为允许我以编程方式编辑查询字符串参数的结构?
Also how can I parse a String
containing a URL with query string parameters into a structure that allows me to edit the query string parameters programmatically?
推荐答案
以下库可以帮助您解析和构建带有查询字符串参数的URL(免责声明:这是我自己的库): https://github.com/lemonlabsuk/scala-uri
The following library can help you parse and build URLs with query string parameters (Disclaimer: This is my own library): https://github.com/lemonlabsuk/scala-uri
它提供了DSL来构建带有查询字符串的URL:
It provides a DSL for building URLs with query strings:
val uri = "http://example.com" ? ("one" -> 1) & ("two" -> 2)
您可以解析uri并将参数放入Map[String,List[String]]
中,如下所示:
You can parse a uri and get the parameters into a Map[String,List[String]]
like so:
val uri = parseUri("http://example.com?one=1&two=2").query.params
这篇关于Scala-具有查询字符串解析器和Builder DSL的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!