Hello World with Play 2

To create a simple Hello World REST service in Play 2, we first need to set up the SBT project correctly. Play 2 uses an SBT plugin to run an HTTP server that you can use to access your REST service. The first thing we need to do is add this plugin to the plugins.sbt file (which you can find in the project directory):

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0")

Next, we define the dependencies so that we can create a Play 2-based REST service. For Play 2, we use the following dependencies:

lazy val playVersion = "2.4.0"

val backendDeps = Seq (
  "com.typesafe.play" %% "play" % playVersion,
  "com.typesafe.play" %% "play-docs" % playVersion

There is one more step we need to add to the SBT configuration (build.sbt ...

Get RESTful Web Services with Scala now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.