Working with HTTP
As Scala can import and invoke Java classes as well as extend them, many of the Scala libraries available as part of the Scala ecosystem are only a thin layer on top of robust and mature Java libraries, to either provide additional features or simplify their usage by adding some syntactic sugar.
One such example is the Scala dispatch library (available at http://dispatch.databinder.net/Dispatch.html), a useful library to achieve HTTP interaction based on Apache's robust HttpClient. Let's run a little dispatch session in the REPL.
As dispatch is an external library; we first need to import it into our SBT project to be able to use it from the REPL console. Add the dispatch dependency to the build.sbt
file of the SampleProject
so that it looks like the following code snippet (make sure to have a blank line between statements in build.sbt
):
name := "SampleProject" … libraryDependencies += "net.databinder.dispatch" %% "dispatch-core" % "0.11.0"
Restart the REPL to make the libraries...