Home Computer Science Building Applications with Scala
Creating a Scala client
First, you will need to create a new project. Go to your file system and create a folder called rest-client. Then, create another folder inside rest-client called project. Inside project, you will need to add the following two files:
Let's start with build.properties: sbt.version=0.13.11
As you can see here, we are configuring this project to use SBT version 0.13.11. Now, we can move to the plugins file.
Your plugins.sbt file should look something like this:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" %
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
Here, we are adding Eclipse and IntelliJ support. For this book, we are using Eclipse, but feel free to use anything you like.
Outside of the project folder, under rest-client, we will need to configure the build.sbt file.
Your build.sbt file should look something like this:
name := "rest-client" version := "1.0" scalaVersion := "2.11.7" scalaVersion in ThisBuild := "2.11.7" resolvers += DefaultMavenRepository resolvers += JavaNet1Repository resolvers += "OSSSonatype" at
Design Your REST API
resolvers += "Sonatype OSS Snapshots" at
"https://oss.sonatype.org/content/repositories/snapshots" resolvers += "Sonatype OSS Snapshots" at
"https://oss.sonatype.org/content/repositories/snapshots" resolvers += "amateras-repo" at "http://amateras.sourceforge.jp/mvn/"
libraryDependencies += "com.typesafe.play" % "play-ws_2.11" % "2.5.6"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.6" % Test
So here, we are using Scala version 2.11.7, and we are declaring just two dependencies. One dependency is for tests, which is scala-test, and the other dependency is on the Play framework ws library, which we will use to call our REST APIs. Let's also create two source folders, as follows: • src/main/scala: This is the Scala source code • src/test/scala: This is the Scala test source code OK. Now we can run $ sbt clean compile eclipse in order to download the dependencies from the web and create all the Eclipse project files that we need.
Now we can import this code in Eclipse and move on.
|< Prev||CONTENTS||Next >|