In Scala how do I build up a URL with query string parameters programmatically?
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?
In Scala how do I build up a URL with query string parameters programmatically?
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?
also useful: https://github.com/mobiworx/urlifier
Spray has a very efficient URI parser. Usage is like so:
You can set the query params like so:
Dispatch hasn't been mentioned yet.
http://dispatch.databinder.net/Dispatch.html
Theon's library looks pretty nice. But if you just want a quickie encode method, I have this one. It deals with optional parameters, and also will recognize JsValues from spray-json and compact print them before encoding. (Those happen to be the two things I have to worry about, but you could easily extend the match block for other cases you want to give special handling to)
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
It provides a DSL for building URLs with query strings:
You can parse a uri and get the parameters into a
Map[String,List[String]]
like so: