1

Hi I am turning here as a last resort but I'm at my wits end. I was trying to learn dispatch so I can do my next web project in scala but I can't even make it past the tutorial. This is what I'm trying to do.

import dispatch._
val h = new Http
val req = url("http://www.scala-lang.org/")
val handler = req >>> System.out

In the sbt console the first 3 lines work correctly but I get an error on the last that value >>> is not a member of com.ning.http.client.RequestBuilder@6eb7546d. Googling this error has honestly been less than insightful. When trying to put this into a .scala file and run it It errors out on the import dispatch._ line. I honestly have no idea what I'm doing wrong here and would kill for some help right now. This can't be as hard as it seems. Also I've installed sbt and followed these directions found at the dispatch home page:

echo 'libraryDependencies += 
  "net.databinder.dispatch" %% "dispatch-core" % "0.9.5"' > build.sbt
sbt console

I additionally have a build.sbt folder containing the following

libraryDependencies +=
"net.databinder.dispatch" %% "dispatch-core" % "0.9.5"
Urist McDev
  • 498
  • 3
  • 14
dcole2929
  • 357
  • 2
  • 11
  • When you say "put this into a .scala file and run it It errors out on the import dispatch._ line" Where did you put that scala file? and how did you run it? – Emil L Mar 09 '13 at 07:36
  • Also the error your getting is because there is no method `>>>` in the class `RequestBuilder`. What is it you try to achieve with `val handler = req >>> System.out`? – Emil L Mar 09 '13 at 07:52
  • was trying to create a handler that outputs the return from the request to the console but >>> is for 0.8.x and apparently 0.9.5 is completely different. What is 0.9.5 equivalent? – dcole2929 Mar 09 '13 at 08:32
  • @dcole2929 on 0.9.x you call a `for comprehension` on the resulting `promise` and do whatever you need with the response. The tutorial for example creates a promise of countries and calls `for (c <- countries) println(c)` – pagoda_5b Mar 10 '13 at 19:59

2 Answers2

4

My best bet is that you're referring to some old tutorial for an outdated version of the library.

Version 0.9.x was totally revised wrt 0.8.x

I suggest you look at the dispatch page and follow the simple steps provided there.

pagoda_5b
  • 7,333
  • 1
  • 27
  • 40
  • I literally just figured that out like 10 minutes ago. I was using the tutorial from 0.8.x because it actually had info about project setup. Not sure why that's not included for 0.9.5 – dcole2929 Mar 09 '13 at 08:31
1

If you're at your wits end with Dispatch, so was I. So here's a shameless plug for my alternative Bee-Client HTTP client api:

val httpClient = new HttpClient
val response: Response = httpClient.get("http://www.google.com/")
println(response.status)
println(response.body.asString)

It's explicitly simple and blocking. If you want non-blocking requests, just wrap the calls in futures.

Rick-777
  • 9,714
  • 5
  • 34
  • 50