SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
• Backed by Lightbend

• Scala 2.12 Support

• HTTP/2 Support

• Native on Java / Scala

• OWASP Compatible
Why Play ?”
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
• app - Java / Scala code

• conf - configuration file

• project - scala plugins

• test - Java / Scala test code

• build.sbt - sbt build file

• README.md

• Dockerfile
Directory Structure
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
organization := "in.norbor"
name := "play-rest"
version := "beta"
sources in(Compile, doc) := Seq.empty
publishArtifact in(Compile, packageDoc) := false
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.12.6"
scalacOptions := Seq("-feature", "-deprecation", "-unchecked")
routesGenerator := InjectedRoutesGenerator
libraryDependencies ++= Seq(
jdbc
exclude("com.h2database", "h2")
exclude("com.jolbox", "bonecp")
, ehcache, guice
, "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.9.5"
, "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0"
, "net.codingwell" %% "scala-guice" % "4.2.1"
, "joda-time" % "joda-time" % "2.9.9"
)
libraryDependencies ++= Seq(
"com.h2database" % "h2" % "1.4.194" % Test
, "com.jolbox" % "bonecp" % "0.8.0.RELEASE" % Test
, "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.1" % Test
)
Simple(?) Build Tool
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
OPTIONS / controllers.RootController.rootOptions
OPTIONS /*url controllers.RootController.options(url: String)
GET /version controllers.RootController.version
POST /registration controllers.registration.Controller.post
POST /sum controllers.sum.Controller.post
# Resources
GET /assets/*file controllers.Assets.at(path="/public", file)
routes
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
include "common"
include "version"
# Environment
# production| staging| development| local
environment = "local"
play {
modules {
enabled += "facades.audit.Module"
enabled += "facades.security.Module"
}
}
db {
default {
hikaricp {
dataSourceClassName = org.postgresql.ds.PGSimpleDataSource
dataSource {
url = "jdbc:postgresql://localhost:5432/seed"
databaseName = "seed"
user = “norbor"
password = ""
}
}
}
}
application.conf
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
package controllers.registration
import javax.inject.{Inject, Singleton}
import play.api.db.Database
import play.api.mvc.{AbstractController, Action, ControllerComponents, Request}
import services.Json
@Singleton
class Controller @Inject()(cc: ControllerComponents
, json: Json
, db: Database)
extends AbstractController(cc) {
def post: Action[String] = Action(parse.tolerantText) { implicit request =>
request.toForm[Form].map (form => {
Ok
}).getOrElse {
BadRequest
}
}
implicit class HTTPRequest(request: Request[String]) {
def toForm[T: Manifest]: Option[T] = json.toClass[T](request.body)
}
}
case class Form(email: String, name: String, password: String)
Controller
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
import abstractspec.UnitSpec
import com.typesafe.scalalogging.LazyLogging
import play.api.test.FakeRequest
import play.api.test.Helpers.{POST, route, status, _}
class ControllerSpec extends UnitSpec with LazyLogging {
private lazy val R1 = (POST, "/registration")
s"${R1._1} ${R1._2}" should {
"return 200 with right json post" in {
val res = route(app, FakeRequest(R1._1, R1._2)
.withHeaders(
("Content-Type", "application/json"))
.withBody(
"""
|{
| "email" : "nb@beid.io"
| , "name" : "Boat"
| , "password" : "yo!!!!!!"
|}
""".stripMargin)
).get
status(res) mustBe OK
logger.info(contentAsString(res))
}
}
}
ControllerSpec
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
$> sbt compile 

$> sbt test

$> sbt dist
Developer Friendly with Terminal
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
Skywalker:~/Github/play-rest (db)$ sbt clean dist
[info] Loading settings from idea.sbt ...
[info] Loading global plugins from /Users/nuboat/.sbt/1.0/plugins
[info] Loading settings from plugins.sbt ...
[info] Loading project definition from /Users/nuboat/Github/play-rest/project
[info] Loading settings from build.sbt ...
[info] Set current project to play-rest (in build file:/Users/nuboat/Github/play-rest/)
[success] Total time: 0 s, completed Jun 23, 2018 11:50:56 AM
[info] Packaging /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta-sources.jar ...
[info] Done packaging.
[info] Wrote /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta.pom
[info] Packaging /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta-web-assets.jar ...
[info] Done packaging.
[info] Compiling 18 Scala sources and 2 Java sources to /Users/nuboat/Github/play-rest/target/scala-2.12/classes ...
[info] Done compiling.
[info] Packaging /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta.jar ...
[info] Done packaging.
[info] Packaging /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta-sans-externalized.jar ...
[info] Done packaging.
[info] Your package is ready in /Users/nuboat/Github/play-rest/target/universal/play-rest-beta.zip
[success] Total time: 15 s, completed Jun 23, 2018 11:51:11 AM
[INFO] [06/23/2018 11:51:11.748] [Thread-2] [CoordinatedShutdown(akka://sbt-web)] Starting coordinated shutdown from JVM
shutdown hook
Skywalker:~/Github/play-rest (db)$ cd target/universal/
Skywalker:~/Github/play-rest/target/universal (db)$ unzip
play-rest-beta.zip scripts/
Skywalker:~/Github/play-rest/target/universal (db)$ unzip play-rest-beta.zip -d release
Archive: play-rest-beta.zip
inflating: release/lib/org.reactivestreams.reactive-streams-1.0.2.jar
inflating: release/lib/in.norbor.play-rest-beta-sans-externalized.jar
. . .
[Skywalker:~/Github/play-rest/target/universal (db)$ ll
total 81304
-rw-r--r-- 1 nuboat staff 41594693 Jun 23 11:51 play-rest-beta.zip
drwxr-xr-x 6 nuboat staff 192 Jun 23 11:52 release
drwxr-xr-x 3 nuboat staff 96 Jun 23 11:51 scripts
Skywalker:~/Github/play-rest/target/universal (db)$ ls release/
README.md bin conf lib
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
#
# Alpine Java 8
#
# https://hub.docker.com/r/anapsix/alpine-java/
# https://github.com/anapsix/docker-alpine-java
#
# Pull base image.
FROM anapsix/alpine-java:8_server-jre
ENV JAVA_HOME /opt/jdk
RUN apk add --update unzip
COPY target/universal/*.zip /root/build.zip
RUN unzip /root/build.zip -d /root/release
# Define working directory.
WORKDIR /root
# Define default command.
CMD exec /root/release/bin/play-rest 
-Dhttp.address=0.0.0.0 
-J-Xms128M -J-Xmx512m 
-Dconfig.file=/root/release/conf/production.conf 
-Dlogger.resource=/root/release/conf/production.xml
Docker Compatible
© 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
“play-rest-scala”
Available on Github

Weitere ähnliche Inhalte

Mehr von Peerapat Asoktummarungsri (6)

Roboguice
RoboguiceRoboguice
Roboguice
 
Homeloan
HomeloanHomeloan
Homeloan
 
Lightweight javaEE with Guice
Lightweight javaEE with GuiceLightweight javaEE with Guice
Lightweight javaEE with Guice
 
Hadoop
HadoopHadoop
Hadoop
 
Meet Django
Meet DjangoMeet Django
Meet Django
 
Easy java
Easy javaEasy java
Easy java
 

Kürzlich hochgeladen

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 

Kürzlich hochgeladen (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 

REST API with Scala Playframework

  • 1. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018
  • 2. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 • Backed by Lightbend • Scala 2.12 Support • HTTP/2 Support • Native on Java / Scala • OWASP Compatible Why Play ?”
  • 3. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 • app - Java / Scala code • conf - configuration file • project - scala plugins • test - Java / Scala test code • build.sbt - sbt build file • README.md • Dockerfile Directory Structure
  • 4. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 organization := "in.norbor" name := "play-rest" version := "beta" sources in(Compile, doc) := Seq.empty publishArtifact in(Compile, packageDoc) := false lazy val root = (project in file(".")).enablePlugins(PlayScala) scalaVersion := "2.12.6" scalacOptions := Seq("-feature", "-deprecation", "-unchecked") routesGenerator := InjectedRoutesGenerator libraryDependencies ++= Seq( jdbc exclude("com.h2database", "h2") exclude("com.jolbox", "bonecp") , ehcache, guice , "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.9.5" , "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0" , "net.codingwell" %% "scala-guice" % "4.2.1" , "joda-time" % "joda-time" % "2.9.9" ) libraryDependencies ++= Seq( "com.h2database" % "h2" % "1.4.194" % Test , "com.jolbox" % "bonecp" % "0.8.0.RELEASE" % Test , "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.1" % Test ) Simple(?) Build Tool
  • 5. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 # Routes # This file defines all application routes (Higher priority routes first) # ~~~~ OPTIONS / controllers.RootController.rootOptions OPTIONS /*url controllers.RootController.options(url: String) GET /version controllers.RootController.version POST /registration controllers.registration.Controller.post POST /sum controllers.sum.Controller.post # Resources GET /assets/*file controllers.Assets.at(path="/public", file) routes
  • 6. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 include "common" include "version" # Environment # production| staging| development| local environment = "local" play { modules { enabled += "facades.audit.Module" enabled += "facades.security.Module" } } db { default { hikaricp { dataSourceClassName = org.postgresql.ds.PGSimpleDataSource dataSource { url = "jdbc:postgresql://localhost:5432/seed" databaseName = "seed" user = “norbor" password = "" } } } } application.conf
  • 7. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 package controllers.registration import javax.inject.{Inject, Singleton} import play.api.db.Database import play.api.mvc.{AbstractController, Action, ControllerComponents, Request} import services.Json @Singleton class Controller @Inject()(cc: ControllerComponents , json: Json , db: Database) extends AbstractController(cc) { def post: Action[String] = Action(parse.tolerantText) { implicit request => request.toForm[Form].map (form => { Ok }).getOrElse { BadRequest } } implicit class HTTPRequest(request: Request[String]) { def toForm[T: Manifest]: Option[T] = json.toClass[T](request.body) } } case class Form(email: String, name: String, password: String) Controller
  • 8. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 import abstractspec.UnitSpec import com.typesafe.scalalogging.LazyLogging import play.api.test.FakeRequest import play.api.test.Helpers.{POST, route, status, _} class ControllerSpec extends UnitSpec with LazyLogging { private lazy val R1 = (POST, "/registration") s"${R1._1} ${R1._2}" should { "return 200 with right json post" in { val res = route(app, FakeRequest(R1._1, R1._2) .withHeaders( ("Content-Type", "application/json")) .withBody( """ |{ | "email" : "nb@beid.io" | , "name" : "Boat" | , "password" : "yo!!!!!!" |} """.stripMargin) ).get status(res) mustBe OK logger.info(contentAsString(res)) } } } ControllerSpec
  • 9. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 $> sbt compile $> sbt test $> sbt dist Developer Friendly with Terminal
  • 10. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 Skywalker:~/Github/play-rest (db)$ sbt clean dist [info] Loading settings from idea.sbt ... [info] Loading global plugins from /Users/nuboat/.sbt/1.0/plugins [info] Loading settings from plugins.sbt ... [info] Loading project definition from /Users/nuboat/Github/play-rest/project [info] Loading settings from build.sbt ... [info] Set current project to play-rest (in build file:/Users/nuboat/Github/play-rest/) [success] Total time: 0 s, completed Jun 23, 2018 11:50:56 AM [info] Packaging /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta-sources.jar ... [info] Done packaging. [info] Wrote /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta.pom [info] Packaging /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta-web-assets.jar ... [info] Done packaging. [info] Compiling 18 Scala sources and 2 Java sources to /Users/nuboat/Github/play-rest/target/scala-2.12/classes ... [info] Done compiling. [info] Packaging /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta.jar ... [info] Done packaging. [info] Packaging /Users/nuboat/Github/play-rest/target/scala-2.12/play-rest_2.12-beta-sans-externalized.jar ... [info] Done packaging. [info] Your package is ready in /Users/nuboat/Github/play-rest/target/universal/play-rest-beta.zip [success] Total time: 15 s, completed Jun 23, 2018 11:51:11 AM [INFO] [06/23/2018 11:51:11.748] [Thread-2] [CoordinatedShutdown(akka://sbt-web)] Starting coordinated shutdown from JVM shutdown hook Skywalker:~/Github/play-rest (db)$ cd target/universal/ Skywalker:~/Github/play-rest/target/universal (db)$ unzip play-rest-beta.zip scripts/ Skywalker:~/Github/play-rest/target/universal (db)$ unzip play-rest-beta.zip -d release Archive: play-rest-beta.zip inflating: release/lib/org.reactivestreams.reactive-streams-1.0.2.jar inflating: release/lib/in.norbor.play-rest-beta-sans-externalized.jar . . . [Skywalker:~/Github/play-rest/target/universal (db)$ ll total 81304 -rw-r--r-- 1 nuboat staff 41594693 Jun 23 11:51 play-rest-beta.zip drwxr-xr-x 6 nuboat staff 192 Jun 23 11:52 release drwxr-xr-x 3 nuboat staff 96 Jun 23 11:51 scripts Skywalker:~/Github/play-rest/target/universal (db)$ ls release/ README.md bin conf lib
  • 11. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 # # Alpine Java 8 # # https://hub.docker.com/r/anapsix/alpine-java/ # https://github.com/anapsix/docker-alpine-java # # Pull base image. FROM anapsix/alpine-java:8_server-jre ENV JAVA_HOME /opt/jdk RUN apk add --update unzip COPY target/universal/*.zip /root/build.zip RUN unzip /root/build.zip -d /root/release # Define working directory. WORKDIR /root # Define default command. CMD exec /root/release/bin/play-rest -Dhttp.address=0.0.0.0 -J-Xms128M -J-Xmx512m -Dconfig.file=/root/release/conf/production.conf -Dlogger.resource=/root/release/conf/production.xml Docker Compatible
  • 12. © 2018, Peerapat AsoktummarungsriV 1.0, Play 2.6.15, Java 8 on June 23, 2018 “play-rest-scala” Available on Github