Menu
Home
Log in / Register
 
Home arrow Computer Science arrow Building Applications with Scala
Source

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:

  • • build.properties: This contains an SBT configuration, such as version
  • • Plugins.sbt: This contains an SBT plugins configuration

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.

Configuring plugins.sbt

Your plugins.sbt file should look something like this:

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" %

"2.5.0")

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.

Configuring build.sbt

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

"https://oss.sonatype.org/content/repositories/releases

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.

 
Source
Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >
 
Subjects
Accounting
Business & Finance
Communication
Computer Science
Economics
Education
Engineering
Environment
Geography
Health
History
Language & Literature
Law
Management
Marketing
Mathematics
Political science
Philosophy
Psychology
Religion
Sociology
Travel