httpget

Scala: How to get content from a REST URL (get REST content)

Here's a simple way to get content from a REST web service using Scala:

object GetUrlContent extends App {

  val url = "http://api.hostip.info/get_json.php?ip=12.215.42.19"
  val result = scala.io.Source.fromURL(url).mkString
  println(result)

}

That's a simple, "new" way I do it with Scala. However, note that it handles timeouts very poorly, such as if the web service you're calling is down or running slowly.

FWIW, here's an old approach I used to retrieve REST content (content from a REST URL):