1

I'm building an API with Rapture in Scala and having trouble resolving an issue with an implicit not being in scope. Here is the output from the error that I'm receiving.

[error] /Users/Petesta/Documents/scala-project/src/main/scala/scala-project/main.scala:35: an implicit TimeSystem is required; please import timeSystems.numeric or timeSystems.javaUtil
[error] Error occurred in an application involving default arguments.
[error]     val response = h.get()
[error]                         ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 5 s, completed Oct 16, 2014 3:36:10 PM

Here is the code that it is failing on.

def getUser(userName: String) = {
    val h = Http / "some_url" / "user" / userName /? Map('key -> "value")
    val response = h.get()
}

I'm not sure what to do because I've tried importing both libraries separately and the error is still the same.

I've also added the -Xlog-implicits flag to see if something else is causing the error but no additional information is outputted.

Is there a good resource anywhere with using the rapture-net library for HTTP requests? I couldn't find one except for Jon Pretty's slides at Scala By The Bay. I couldn't figure out a way to pass in a url with query strings into rapture-uri since it expects function invocation to look like this uri"url_dot_domain_with_query_strings".slurp[Char].

Any ideas?

pagoda_5b
  • 7,333
  • 1
  • 27
  • 40
Petesta
  • 1,623
  • 3
  • 19
  • 29

1 Answers1

2

The compilation error is not entirely correct in this case. You need 1 of the 2 imports AND you need to specify a timeout value.

def getUser(userName: String) = {
  import timeSystems.numeric
  val h = Http / "some_url" / "user" / userName /? Map('key -> "value")
  val response = h.get(timeout = 5000L)
}

I don't really know of a good resource on it, but your basic single code line is correct. The biggest problem with the library is really documentation about the imports required. But this is what I found works for me:

def getGoogle() = {
  import rapture.codec._
  import rapture.io._
  import rapture.uri._
  import rapture.net._
  import encodings.`UTF-8`
  uri"http://google.com".slurp[Char]
}
vossim
  • 21
  • 3