Introduction to – Play Framework – Working with Play



Introduction to – Play Framework – Working with Play

0 0


introduction-to-play

presentation : Introduction to Play Framework

On Github sergiuszkierat / introduction-to-play

Introduction to

Play Framework

2.5.x

Created by @kierat_s

How many of you used Play Framework? How many of you is familiar/developer with Typesafe/Lightbend stack?

Who am I?

  • married father-of-two
  • runner
  • mountain addicted
  • JVM, since 2006
  • Scala enthusiast
  • working at Javeo

Agenda

Getting started Demo Feel free to break me if you need Goal: encourage to use Play Framework as fast development framework

Working with Play

  • Play for Java developers
  • Play for Scala developers
“The API available directly inside the play package (such as play.mvc) is reserved for Java developers. As a Scala developer, look at play.api.mvc.”
  • Java API - play, e.g. play.mvc
  • Scala API - play.api, e.g. play.api.mvc

Getting started

download add activator to PATH creating a new application Play console setting up your preferred IDE anatomy of a Play application Feel free to break me if you need minimal or full whereis activator ui -> new Play Java Seed, activator new -> play-scala + run with UI and CLI Launching, help, run(compile errors), compile, test, console - views.html.index("uuu"), ~

Demo

  • change text Application.index, fast development
  • do a blunder, compile error, don't worry, visible only in dev mode
  • templates in scala, possible to use e.g. groovy, composition
  • @play20.welcome(message) -> @message
  • ApplicationSpec
  • browser test, IntegrationSpec
  • run and fix test, testQuick
  • ----------
  • debugging
  • create models.Company
  • object Company -> implicit val companyFormat -> Json.format[Company]
  • POST /company controllers.Application.addCompany
  • dependency from github, import sorm._, only for presentation, Slick
  • from site, object DB extends Instance(entities = Seq(Entity[Company]()), url = "jdbc:h2:mem:test") {
  • curl -H "Content-Type: application/json" -X POST -d '{}' http://localhost:9000/company
  • val companyForm: Form[Company] = Form { mapping( "name" -> text )(Company.apply)(Company.unapply) }
  • val company = companyForm.bindFromRequest.get DB.save(Company) Redirect(routes.Application.index())
  • form action="@routes.Application.addCompany()" method="post"> input name="name" type="text"/ button>Add Company
  • GET /companies controllers.Application.getCompanies refresh i show
  • val companies = DB.query[Company].fetch() Ok(Json.toJson(companies))
  • plugins.sbt
  • $ -> $.get "/companies", (companies) -> $.each companies, (index, company) -> $("#companies").append $("
  • ").text company.name
  • script src='@routes.Assets.versioned("js/index.js")'
  • webjars

Thanks

search template by Javeo string
1
Introduction to Play Framework 2.5.x Created by @kierat_s How many of you used Play Framework? How many of you is familiar/developer with Typesafe/Lightbend stack?