2

I'm using the excellent Dispatch library to make HTTP requests like so:

Http(url("http://foo.bar/baz").GET <<? Map("param1" -> "value1") OK as.String)

However, I'm talking to a REST service that expects param1 to be a list of values. How can I accomplish this in Dispatch?

I see in the source code that <<? takes a Traversable[(String,String)], so maybe it is as easy as passing a Traversable that allows keys to appear multiple times. Is there such a beast? I've been poking through the Scala API docs, but I can't find one that would seem to fit the bill.

Failing that, is there a way to hook into the request builder? I see that Dispatch uses a com.ning.http.client.RequestBuilder, on which I could call addQueryParameter() myself.

Urist McDev
  • 498
  • 3
  • 14
Josh Glover
  • 25,142
  • 27
  • 92
  • 129

1 Answers1

4

Well, after a bit more slogging through the Scala API docs, I had an epiphany! List itself mixes in Traversable, so a list of something for which apply(String, String) will do the trick. Tuples to the rescue:

Http(url("http://foo.bar/baz").GET <<? List(("param1" -> "value1"), ("param1" -> "value2")) OK as.String)
Josh Glover
  • 25,142
  • 27
  • 92
  • 129
  • What did you import for this example to work? I get `cannot resolve method "Http.apply"`. – Neil May 17 '13 at 16:45