SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
Quick bootstrap into
PlayFramework (2.1.x)

Łukasz Wójcik
First step
● Download PlayFramework from www.
playframework.com/download
● Add corresponding path to PATH
● Check if it works calling

>play help
Creating and running an Application
Navigate to your projects directory, and type
>play new application-name
>cd applicaiton-name
>play ~run
Open http://localhost:9090 in your favourite
browser (if your favourite browser is IE - open
it in Chrome ;)
Generated dirs structure
app

→ Application sources

└ assets

→ Compiled asset sources (stylesheets and javascripts)

└ controllers

→ Application controllers

└ models

→ Application business layer

└ views

→ Templates

build.sbt

→ Application build script

conf

→ Configurations files and other non-compiled resources (on classpath)

└ application.conf
└ routes

→ Main configuration file
→ Routes definition

public

→ Public assets

└ stylesheets

→ CSS files

└ javascripts

→ Javascript files

└ images

→ Image files

project

→ sbt configuration files

└ build.properties
└ plugins.sbt
lib
logs

→ sbt plugins including the declaration for Play itself
→ Unmanaged libraries dependencies
→ Standard logs folder

└ application.log
target

→ Marker for sbt project

→ Default log file
→ Generated stuff (including generated sources out of scala views)

└ scala-2.10.0
test

→ source folder for unit or functional tests
Basic play console commands
Workflow commands:
>play compile
>play run
>play test
>play clean-all
>play debug
>play eclise #generates eclipse project to use with ScalaIde 3.0.2
auto triggering (as in SBT)
>play ~ compile|run|test
Application development
● Global Application Object
- can control life-time events in an app

● Controllers
- do hard work around HTTP requests

● Routing
- binds requested URLs with particular Controllers

● Predefined results
● Sessions and Flashes
● Async results
Global Application Object
import play.api.GlobalSettings
import play.api.mvc.RequestHeader
import play.api.mvc.Handler
import play.api.Logger
object Global extends GlobalSettings {
override def onRouteRequest(request:RequestHeader):Option
[Handler] = {
Logger.debug("on Request Routed" + request)
super.onRouteRequest(request)
}
}
In application.conf
application.global=app.Global
Controllers
import play.api.mvc.Controller
import play.api.mvc.Results._
import play.api.mvc.Action
object Tasks extends Controller {
def list = Action {
Ok("it works")
}
}
GET

/tasks

controllers.Tasks.list
Views
● Are in 90% in HTML + Scala-like expression
● Are compiled to Scala Objects
● View class is actually a … method body
We can create a reusable layout of a webapp:
views/templates/tasks.scala.html
and use it to form result content
views/tasks/list.scala.html
Models (DAOs and Entities)
We need a dependency for MySQL JDBC connector
in Build.scala we add
"mysql" % "mysql-connector-java" % "5.1.18",
in application.conf we add (to see SQL stmnts) :
db.default.logStatements=true
More at
http://www.playframework.com/documentation/2.1.x/ScalaDatabase
Models (DAOs and Entities)
import play.api.Play.current //imports current application
object into scope
import play.api.db._ //imports DB api (facade for JDBC)
//Retreiving connection
val ds = DB.getDataSource()
//lub
val connection = DB.getConnection()
//lub
DB.withConnection("default") { conn =>
// do whatever you need with the connection
}
… so let’s create an Entity and DAO and do some coding
… after coding - time to sum up
●
●
●
●
●
●
●
●

Native JSON and XML support
Powerful routing syntax
Web Services client (sync, async)
Build in translations management
Asynchronous HTTP programming
Less/CoffeScript support
ClosureCompiler/RequireJS support
many many more ;)
THE END
Lukasz Wójcik

Contenu connexe

En vedette

Bcg Consultants Love Life
Bcg  Consultants Love LifeBcg  Consultants Love Life
Bcg Consultants Love Lifenitinagarwalin
 
Lab session #2: The Human Company
Lab session #2: The Human CompanyLab session #2: The Human Company
Lab session #2: The Human CompanyLuminary Labs
 
e-conomy SEA by Google and Temasek
e-conomy SEA by Google and Temaseke-conomy SEA by Google and Temasek
e-conomy SEA by Google and TemasekeconomySEA
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakShelly Sanchez Terrell
 
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013Cain Ransbottyn
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?Maciej Lasyk
 
Great Talks Start with Great Proposals: An IA Summit Virtual Webinar
Great Talks Start with Great Proposals: An IA Summit Virtual WebinarGreat Talks Start with Great Proposals: An IA Summit Virtual Webinar
Great Talks Start with Great Proposals: An IA Summit Virtual WebinarRuss U
 
Designing a Culture of Design
Designing a Culture of DesignDesigning a Culture of Design
Designing a Culture of DesignChris Avore
 
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitroMobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitroTorsten Schollmayer
 
Entrepreneurshit. The Truth About Building Starutps
Entrepreneurshit. The Truth About Building StarutpsEntrepreneurshit. The Truth About Building Starutps
Entrepreneurshit. The Truth About Building StarutpsMark Suster
 
Subscribed 2015: CEO's Keynote
Subscribed 2015: CEO's KeynoteSubscribed 2015: CEO's Keynote
Subscribed 2015: CEO's KeynoteZuora, Inc.
 

En vedette (14)

Docker.io
Docker.ioDocker.io
Docker.io
 
Bcg Consultants Love Life
Bcg  Consultants Love LifeBcg  Consultants Love Life
Bcg Consultants Love Life
 
Lab session #2: The Human Company
Lab session #2: The Human CompanyLab session #2: The Human Company
Lab session #2: The Human Company
 
e-conomy SEA by Google and Temasek
e-conomy SEA by Google and Temaseke-conomy SEA by Google and Temasek
e-conomy SEA by Google and Temasek
 
Teaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & TextspeakTeaching Students with Emojis, Emoticons, & Textspeak
Teaching Students with Emojis, Emoticons, & Textspeak
 
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
Privacy is an Illusion and you’re all losers! - Cryptocow - Infosecurity 2013
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Quantum computing
Quantum computingQuantum computing
Quantum computing
 
Great Talks Start with Great Proposals: An IA Summit Virtual Webinar
Great Talks Start with Great Proposals: An IA Summit Virtual WebinarGreat Talks Start with Great Proposals: An IA Summit Virtual Webinar
Great Talks Start with Great Proposals: An IA Summit Virtual Webinar
 
Designing a Culture of Design
Designing a Culture of DesignDesigning a Culture of Design
Designing a Culture of Design
 
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitroMobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
Mobile Trends 2012 - MDAYS by Torsten Schollmayer, SapientNitro
 
Entrepreneurshit. The Truth About Building Starutps
Entrepreneurshit. The Truth About Building StarutpsEntrepreneurshit. The Truth About Building Starutps
Entrepreneurshit. The Truth About Building Starutps
 
Subscribed 2015: CEO's Keynote
Subscribed 2015: CEO's KeynoteSubscribed 2015: CEO's Keynote
Subscribed 2015: CEO's Keynote
 
The Hierarchy of Engagement
The Hierarchy of EngagementThe Hierarchy of Engagement
The Hierarchy of Engagement
 

Dernier

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Dernier (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Quick Bootstrap to PlayFramework 2.1t

  • 1. Quick bootstrap into PlayFramework (2.1.x) Łukasz Wójcik
  • 2. First step ● Download PlayFramework from www. playframework.com/download ● Add corresponding path to PATH ● Check if it works calling >play help
  • 3. Creating and running an Application Navigate to your projects directory, and type >play new application-name >cd applicaiton-name >play ~run Open http://localhost:9090 in your favourite browser (if your favourite browser is IE - open it in Chrome ;)
  • 4. Generated dirs structure app → Application sources └ assets → Compiled asset sources (stylesheets and javascripts) └ controllers → Application controllers └ models → Application business layer └ views → Templates build.sbt → Application build script conf → Configurations files and other non-compiled resources (on classpath) └ application.conf └ routes → Main configuration file → Routes definition public → Public assets └ stylesheets → CSS files └ javascripts → Javascript files └ images → Image files project → sbt configuration files └ build.properties └ plugins.sbt lib logs → sbt plugins including the declaration for Play itself → Unmanaged libraries dependencies → Standard logs folder └ application.log target → Marker for sbt project → Default log file → Generated stuff (including generated sources out of scala views) └ scala-2.10.0 test → source folder for unit or functional tests
  • 5. Basic play console commands Workflow commands: >play compile >play run >play test >play clean-all >play debug >play eclise #generates eclipse project to use with ScalaIde 3.0.2 auto triggering (as in SBT) >play ~ compile|run|test
  • 6. Application development ● Global Application Object - can control life-time events in an app ● Controllers - do hard work around HTTP requests ● Routing - binds requested URLs with particular Controllers ● Predefined results ● Sessions and Flashes ● Async results
  • 7. Global Application Object import play.api.GlobalSettings import play.api.mvc.RequestHeader import play.api.mvc.Handler import play.api.Logger object Global extends GlobalSettings { override def onRouteRequest(request:RequestHeader):Option [Handler] = { Logger.debug("on Request Routed" + request) super.onRouteRequest(request) } } In application.conf application.global=app.Global
  • 8. Controllers import play.api.mvc.Controller import play.api.mvc.Results._ import play.api.mvc.Action object Tasks extends Controller { def list = Action { Ok("it works") } } GET /tasks controllers.Tasks.list
  • 9. Views ● Are in 90% in HTML + Scala-like expression ● Are compiled to Scala Objects ● View class is actually a … method body We can create a reusable layout of a webapp: views/templates/tasks.scala.html and use it to form result content views/tasks/list.scala.html
  • 10. Models (DAOs and Entities) We need a dependency for MySQL JDBC connector in Build.scala we add "mysql" % "mysql-connector-java" % "5.1.18", in application.conf we add (to see SQL stmnts) : db.default.logStatements=true More at http://www.playframework.com/documentation/2.1.x/ScalaDatabase
  • 11. Models (DAOs and Entities) import play.api.Play.current //imports current application object into scope import play.api.db._ //imports DB api (facade for JDBC) //Retreiving connection val ds = DB.getDataSource() //lub val connection = DB.getConnection() //lub DB.withConnection("default") { conn => // do whatever you need with the connection } … so let’s create an Entity and DAO and do some coding
  • 12. … after coding - time to sum up ● ● ● ● ● ● ● ● Native JSON and XML support Powerful routing syntax Web Services client (sync, async) Build in translations management Asynchronous HTTP programming Less/CoffeScript support ClosureCompiler/RequireJS support many many more ;)