0

I am trying a simple example where I am using a modification of the Dispatch example from the Scalatra site to make an async http request. The code is below. I get a compilation error that says value OK is not a member of String. I put together a standalone scala test with no Scalatra dependencies and it works as expected. I suspect OK is being pulled in from some Scalatra dependency. I am new to Scala and I am putting together a test web app using Scalatra. Any help will be appreciated.

import dispatch._

trait AppAPIStack extends AppStack {
before() {
  contentType = "application/json"
}

object MyAsyncClient {

   def sendReq(phrase: param): Future[String] = {
     val searchURL = url("https://www.google.com/#q="+phrase)
     val result = dispatch.Http(searchURL OK as.String)
     for(r <- result) yield r
   }

   }
}
VDev
  • 2,287
  • 5
  • 25
  • 27

2 Answers2

2

I fixed the issue by changing the line

url("https://www.google.com/#q="+phrase) 

to

dispatch.url("https://www.google.com/#q="+phrase)

Dispatch and Scalatra base servlet I think have an implementation of url which was clashing. The url version from Scalatra does not return OK.

VDev
  • 2,287
  • 5
  • 25
  • 27
0

First of all inspect type of result. If you use IDE just hover your mouse on it and see what it is actually is. It must be different than Future[String], it is Future[T], find out what is T and how to convert it to String.

Mikhail Golubtsov
  • 6,285
  • 3
  • 29
  • 36