SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
Your First Scala Web Application
using Play! Framework
By Matthew Barlocker
The Barlocker
● Chief Architect at Lucid
Software Inc
● Learned Scala and Play!
“the hard way”.
● Graduated with Bachelors
Degree in Computer Science
from BYU in 2008.
● Developed software for the
following industries:
– Network Security
– Social Gaming
– Financial
– Productivity
Time is Scarce!
Write your questions down
and ask me after the session.
Quick Assessment
● Languages
– Scala
– Java
– PHP
– Ruby
● MVC Frameworks
● Build Tools
– sbt
– maven
– ivy
Get it Running
● Requires Java >= 6 to run
● You need a terminal.
● Add play-2.1.4 directory to PATH
– Linux
● `export PATH=$PATH:/path/play-2.1.4`
● `chmod +x /path/play-2.1.4/play`
– Windows
● Add path to global environment variables
● Don't use a path with spaces
Get it Running
● `cd /parent/dir/for/new/project`
● `play new strangeloop`
● `cd strangeloop`
● `git init` - suggested
● `play [debug]`
– `run [port=9000]`
● Go to http://localhost:9000
Scala Intro
● The current version is 2.10.2.
● Open your cheat sheet for code samples.
● Runs on the JVM.
● 100% inter-operable with Java code (jars).
● Functions are first-class citizens.
● Typed, compiled language.
● Semicolons are inferred.
● Functional language that supports procedural.
Scala Intro - Variables
● val
– immutable
– good for multi-threading
– recommended type of variable
● var
– mutable
– good for procedural code
Scala Intro - Typing
● Colon-postfix notation for typing.
● All variables and functions can be explicitly
typed.
● Some variables and functions can be implicitly
typed.
Scala Intro - Looping
● Most looping is done over lists, arrays, maps,
and other data structures using .foreach() or
.map().
● for (i <- 0 until 10)
– Looping criteria (in parens) is calculated exactly
once.
– Can be used to 'yield' results.
● [do …] while (i < 10)
Scala Intro – Control Structures
● if (condition) … else …
– Returns a value.
– Use instead of a ternary operator.
● match statement
– Similar to a switch, but much more flexible.
– Can match regular expressions, interfaces,
classes, and other extractors.
Scala Intro - Functions
● 'public' is the default access modifier.
● The last value computed is returned.
● Function names can include operators.
– '+' is a function on strings and numbers.
● Parameters must be typed.
● Return value can be inferred.
● Multiple parameter lists are allowed. Not the
same as currying.
Scala Intro - Collections
● Tuples have a length and each element has a
type.
– val a = (5, 2.0, “hello”)
● Maps are key -> value pairs
– val b = Map(1 -> “a”, 2 -> “b”)
● Arrays are mutable
– val c = Array(4, 5, 6)
● Lists are immutable
– val d = List(7, 8, 9)
Scala Intro - Classes
● Case classes get the following for free:
– 'equals', 'toString', 'hashCode', 'copy' functions.
– every class argument is a public val unless
specified otherwise.
● Objects are singleton classes.
– Must be used for static methods.
● Traits are abstract classes.
– No class arguments.
– Used for multiple inheritance or interfaces.
Scala Intro – Console Example
● Variables
● Functions
● Classes
● Options
● Matching
● Lists, Maps
● Iterating
● Function parameters
● Parameter Lists
● Conditionals
Scala Resources
● http://www.scala-lang.org/
● http://www.scala-lang.org/documentation/
● https://groups.google.com/d/forum/scala-user
● irc://irc.freenode.net/scala
● http://www.scala-lang.org/community/
● https://github.com/scala/scala
Play! Intro
● Current version is 2.1.4.
● Play Framework makes it easy to build web
applications with Java & Scala.
● Play is based on a lightweight, stateless, web-
friendly architecture.
● Make your changes and simply hit refresh! All
you need is a browser and a text editor.
Play! Features
● Rebuilds the project when you change files and
refresh the page.
● IDE support for IntelliJ, Eclipse, Sublime, and
more.
● Asset compiler for LESS, CoffeeScript, and
more.
● JSON is a first-class citizen.
Who Uses Play!
Play! Resources
● http://www.playframework.com/
● https://github.com/playframework/playframework
● https://groups.google.com/group/play-framework
● http://www.playframework.com/documentation
● http://twitter.com/playframework
Let's Build It!
Topics
● Request Handling
– URLs
– Controllers
– Actions
– Responses
– HTTP
● Views
– Templates
– Encoding
– Assets
● Forms
– Validation
– Submission
Topics (cont.)
● Database
– Evolutions
– Connections
– Models
– Queries
● Build System
– Dependencies
– Deployment
– Testing
● Application Global
– Request Handling
– Error Handling
– Application Hooks
● I18n
– Strings
– Views
– Configuration
Topics (cont.)
● Testing
– Fake Application
– Fake Requests
– Fake DB
– Patterns
Reminder:
Write your questions down
Request Handling - Terminology
● Route – Mapping of URL/HTTP Method to an
action
● Action – Function that takes a request and
returns a result
● Controller – Action generator
● Request – HTTP headers and body
● Result – HTTP status code, headers, and body
Request Handling - Exercise
● Create a new home page
● Create a page that redirects to the new home page
● Set content type on home page
● Create a page to set, and a page to get:
– Headers
– Cookies
– Session
– Flash
● Create a TODO page
● Use URL parameters and action to send 404
SimpleResults
● Ok
● Created
● Accepted
● MovedPermanently
● Found
● SeeOther
● NotModified
● TemporaryRedirect
● BadRequest
● Unauthorized
● Forbidden
● NotFound
● InternalServerError
● ...
Routes
● Every route has HTTP method, URL, and
action to call.
● URL can include parameters, which are passed
to the action.
● These parameters can be validated and
converted as part of the matching.
● First matching route wins.
Views
● '@' is the magical operator.
● No special functions, it's just embedded Scala code.
● Each view is just a function that can be called from
anywhere.
● Views set the content type automatically.
Views - Exercise
● Create view for URL parameter page.
● Create view for the home page.
● Create template, use it in the home page view.
● Add links to template
● Display flash messages in layout.
● Use implicit request.
Views
● Files are named package/myview.scala.html.
● Views are referenced views.html.package.myview.
● All values are HTML encoded for you.
● Views are not intended to handle big data.
● If broken, play with the whitespace.
Forms - Exercise
● Create a contact form.
● Create a login form. On submit, set a fake user
id in the session.
Forms
● Form.bindFromRequest will use GET and
POST variables.
● There are many constraints and data types.
Explore to find them.
Database - Exercise
● Configure a database connection.
● Create a database evolution for users table.
● Create page and model to register users.
● Update login to check against user list.
● Create page to show current user.
Build System
● Reload play after changing dependencies.
● Find dependencies at http://mvnrepository.com/
● Try a deployment
– `play stage`
– `./target/start -Dhttp.port=9000`
● To deploy, copy target/start and target/staged
to the target system, and run 'start'
I18n - Exercise
● Replace all messages in the layout.
● Add language files
● Configure another language
● Try it in the browser
Testing - Exercise
● Inspect and modify existing tests.
● Run tests from command line.
Time Permitting
● Advanced Request Handling
– EssentialAction
– RequestHeader
– Iteratees
– Filters
● Application Global
Thank you for your time.
Any Questions?
Lucid Software Inc
● Building the next generation of collaborative web
applications
● VC funded, high growth, profitable
● Graduates from Harvard, MIT, Stanford
● Team has worked at Google, Amazon, Microsoft
https://www.lucidchart.com/jobs

Mais conteúdo relacionado

Mais procurados

Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka way
Yardena Meymann
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 

Mais procurados (20)

REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
 
Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka way
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to Laravel
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with Lumen
 
django Forms in a Web API World
django Forms in a Web API Worlddjango Forms in a Web API World
django Forms in a Web API World
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Laravel and Django and Rails, Oh My!
Laravel and Django and Rails, Oh My!Laravel and Django and Rails, Oh My!
Laravel and Django and Rails, Oh My!
 
20171108 PDN HOL React Basics
20171108 PDN HOL React Basics20171108 PDN HOL React Basics
20171108 PDN HOL React Basics
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to Laravel
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Actor Model Akka Framework
Actor Model Akka FrameworkActor Model Akka Framework
Actor Model Akka Framework
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Laravel Webcon 2015
Laravel Webcon 2015Laravel Webcon 2015
Laravel Webcon 2015
 
Cucumber, Cuke4Duke, and Groovy
Cucumber, Cuke4Duke, and GroovyCucumber, Cuke4Duke, and Groovy
Cucumber, Cuke4Duke, and Groovy
 
Java Enterprise Edition Concurrency Misconceptions
Java Enterprise Edition Concurrency Misconceptions Java Enterprise Edition Concurrency Misconceptions
Java Enterprise Edition Concurrency Misconceptions
 

Destaque

Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Magneta AI
 
DUMP-2015: «Распределенная обработка миллионов документов на Scala и Akka» Ст...
DUMP-2015: «Распределенная обработка миллионов документов на Scala и Akka» Ст...DUMP-2015: «Распределенная обработка миллионов документов на Scala и Akka» Ст...
DUMP-2015: «Распределенная обработка миллионов документов на Scala и Akka» Ст...
it-people
 
Введение в Akka
Введение в AkkaВведение в Akka
Введение в Akka
Zheka Kozlov
 
Язык программирования Scala / Владимир Успенский (TCS Bank)
Язык программирования Scala / Владимир Успенский (TCS Bank)Язык программирования Scala / Владимир Успенский (TCS Bank)
Язык программирования Scala / Владимир Успенский (TCS Bank)
Ontico
 

Destaque (20)

Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
 
[Start] Playing
[Start] Playing[Start] Playing
[Start] Playing
 
Playing with Scala
Playing with ScalaPlaying with Scala
Playing with Scala
 
DUMP-2015: «Распределенная обработка миллионов документов на Scala и Akka» Ст...
DUMP-2015: «Распределенная обработка миллионов документов на Scala и Akka» Ст...DUMP-2015: «Распределенная обработка миллионов документов на Scala и Akka» Ст...
DUMP-2015: «Распределенная обработка миллионов документов на Scala и Akka» Ст...
 
Play Template Engine Based On Scala
Play Template Engine Based On ScalaPlay Template Engine Based On Scala
Play Template Engine Based On Scala
 
Designing Reactive Systems with Akka
Designing Reactive Systems with AkkaDesigning Reactive Systems with Akka
Designing Reactive Systems with Akka
 
HTML5 with Play Scala, CoffeeScript and Jade - Devoxx 2011
HTML5 with Play Scala, CoffeeScript and Jade - Devoxx 2011HTML5 with Play Scala, CoffeeScript and Jade - Devoxx 2011
HTML5 with Play Scala, CoffeeScript and Jade - Devoxx 2011
 
Play framework And Google Cloud Platform GCP.
Play framework And Google Cloud Platform GCP.Play framework And Google Cloud Platform GCP.
Play framework And Google Cloud Platform GCP.
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
Введение в Akka
Введение в AkkaВведение в Akka
Введение в Akka
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
 
Akka-http
Akka-httpAkka-http
Akka-http
 
Lagom in Practice
Lagom in PracticeLagom in Practice
Lagom in Practice
 
Spring Scala : 스프링이 스칼라를 만났을 때
Spring Scala : 스프링이 스칼라를 만났을 때Spring Scala : 스프링이 스칼라를 만났을 때
Spring Scala : 스프링이 스칼라를 만났을 때
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scala
 
Akka http 2
Akka http 2Akka http 2
Akka http 2
 
Язык программирования Scala / Владимир Успенский (TCS Bank)
Язык программирования Scala / Владимир Успенский (TCS Bank)Язык программирования Scala / Владимир Успенский (TCS Bank)
Язык программирования Scala / Владимир Успенский (TCS Bank)
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
 
Akka http
Akka httpAkka http
Akka http
 

Semelhante a Your First Scala Web Application using Play 2.1

Angular basicschat
Angular basicschatAngular basicschat
Angular basicschat
Yu Jin
 

Semelhante a Your First Scala Web Application using Play 2.1 (20)

Moodle Development Best Pracitces
Moodle Development Best PracitcesMoodle Development Best Pracitces
Moodle Development Best Pracitces
 
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan KrausHTML, CSS & Javascript Architecture (extended version) - Jan Kraus
HTML, CSS & Javascript Architecture (extended version) - Jan Kraus
 
Dust.js
Dust.jsDust.js
Dust.js
 
Introduction to rails
Introduction to railsIntroduction to rails
Introduction to rails
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadius
 
Beyond Wordcount with spark datasets (and scalaing) - Nide PDX Jan 2018
Beyond Wordcount  with spark datasets (and scalaing) - Nide PDX Jan 2018Beyond Wordcount  with spark datasets (and scalaing) - Nide PDX Jan 2018
Beyond Wordcount with spark datasets (and scalaing) - Nide PDX Jan 2018
 
Amazon DynamoDB Lessen's Learned by Beginner
Amazon DynamoDB Lessen's Learned by BeginnerAmazon DynamoDB Lessen's Learned by Beginner
Amazon DynamoDB Lessen's Learned by Beginner
 
Javascript Update May 2013
Javascript Update May 2013Javascript Update May 2013
Javascript Update May 2013
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotCloud
 
Revealing ALLSTOCKER
Revealing ALLSTOCKERRevealing ALLSTOCKER
Revealing ALLSTOCKER
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Angular basicschat
Angular basicschatAngular basicschat
Angular basicschat
 
Mustache
MustacheMustache
Mustache
 
React - The JavaScript Library for User Interfaces
React - The JavaScript Library for User InterfacesReact - The JavaScript Library for User Interfaces
React - The JavaScript Library for User Interfaces
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
 
Java on Google App engine
Java on Google App engineJava on Google App engine
Java on Google App engine
 
Android training day 4
Android training day 4Android training day 4
Android training day 4
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATION
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tips
 

Mais de Matthew Barlocker

Mais de Matthew Barlocker (10)

Getting Started on Amazon EKS
Getting Started on Amazon EKSGetting Started on Amazon EKS
Getting Started on Amazon EKS
 
Optimizing Uptime in SOA
Optimizing Uptime in SOAOptimizing Uptime in SOA
Optimizing Uptime in SOA
 
Relate
RelateRelate
Relate
 
Highly Available Graphite
Highly Available GraphiteHighly Available Graphite
Highly Available Graphite
 
Nark: Steroids for Graphite
Nark: Steroids for GraphiteNark: Steroids for Graphite
Nark: Steroids for Graphite
 
ORM or SQL? A Better Way to Query in MySQL
ORM or SQL? A Better Way to Query in MySQLORM or SQL? A Better Way to Query in MySQL
ORM or SQL? A Better Way to Query in MySQL
 
Amazon EC2 to Amazon VPC: A case study
Amazon EC2 to Amazon VPC: A case studyAmazon EC2 to Amazon VPC: A case study
Amazon EC2 to Amazon VPC: A case study
 
Case Study: Lucidchart's Migration to VPC
Case Study: Lucidchart's Migration to VPCCase Study: Lucidchart's Migration to VPC
Case Study: Lucidchart's Migration to VPC
 
Git essentials
Git essentialsGit essentials
Git essentials
 
Magic methods
Magic methodsMagic methods
Magic methods
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

Your First Scala Web Application using Play 2.1

  • 1. Your First Scala Web Application using Play! Framework By Matthew Barlocker
  • 2. The Barlocker ● Chief Architect at Lucid Software Inc ● Learned Scala and Play! “the hard way”. ● Graduated with Bachelors Degree in Computer Science from BYU in 2008. ● Developed software for the following industries: – Network Security – Social Gaming – Financial – Productivity
  • 3. Time is Scarce! Write your questions down and ask me after the session.
  • 4. Quick Assessment ● Languages – Scala – Java – PHP – Ruby ● MVC Frameworks ● Build Tools – sbt – maven – ivy
  • 5. Get it Running ● Requires Java >= 6 to run ● You need a terminal. ● Add play-2.1.4 directory to PATH – Linux ● `export PATH=$PATH:/path/play-2.1.4` ● `chmod +x /path/play-2.1.4/play` – Windows ● Add path to global environment variables ● Don't use a path with spaces
  • 6. Get it Running ● `cd /parent/dir/for/new/project` ● `play new strangeloop` ● `cd strangeloop` ● `git init` - suggested ● `play [debug]` – `run [port=9000]` ● Go to http://localhost:9000
  • 7. Scala Intro ● The current version is 2.10.2. ● Open your cheat sheet for code samples. ● Runs on the JVM. ● 100% inter-operable with Java code (jars). ● Functions are first-class citizens. ● Typed, compiled language. ● Semicolons are inferred. ● Functional language that supports procedural.
  • 8. Scala Intro - Variables ● val – immutable – good for multi-threading – recommended type of variable ● var – mutable – good for procedural code
  • 9. Scala Intro - Typing ● Colon-postfix notation for typing. ● All variables and functions can be explicitly typed. ● Some variables and functions can be implicitly typed.
  • 10. Scala Intro - Looping ● Most looping is done over lists, arrays, maps, and other data structures using .foreach() or .map(). ● for (i <- 0 until 10) – Looping criteria (in parens) is calculated exactly once. – Can be used to 'yield' results. ● [do …] while (i < 10)
  • 11. Scala Intro – Control Structures ● if (condition) … else … – Returns a value. – Use instead of a ternary operator. ● match statement – Similar to a switch, but much more flexible. – Can match regular expressions, interfaces, classes, and other extractors.
  • 12. Scala Intro - Functions ● 'public' is the default access modifier. ● The last value computed is returned. ● Function names can include operators. – '+' is a function on strings and numbers. ● Parameters must be typed. ● Return value can be inferred. ● Multiple parameter lists are allowed. Not the same as currying.
  • 13. Scala Intro - Collections ● Tuples have a length and each element has a type. – val a = (5, 2.0, “hello”) ● Maps are key -> value pairs – val b = Map(1 -> “a”, 2 -> “b”) ● Arrays are mutable – val c = Array(4, 5, 6) ● Lists are immutable – val d = List(7, 8, 9)
  • 14. Scala Intro - Classes ● Case classes get the following for free: – 'equals', 'toString', 'hashCode', 'copy' functions. – every class argument is a public val unless specified otherwise. ● Objects are singleton classes. – Must be used for static methods. ● Traits are abstract classes. – No class arguments. – Used for multiple inheritance or interfaces.
  • 15. Scala Intro – Console Example ● Variables ● Functions ● Classes ● Options ● Matching ● Lists, Maps ● Iterating ● Function parameters ● Parameter Lists ● Conditionals
  • 16. Scala Resources ● http://www.scala-lang.org/ ● http://www.scala-lang.org/documentation/ ● https://groups.google.com/d/forum/scala-user ● irc://irc.freenode.net/scala ● http://www.scala-lang.org/community/ ● https://github.com/scala/scala
  • 17. Play! Intro ● Current version is 2.1.4. ● Play Framework makes it easy to build web applications with Java & Scala. ● Play is based on a lightweight, stateless, web- friendly architecture. ● Make your changes and simply hit refresh! All you need is a browser and a text editor.
  • 18. Play! Features ● Rebuilds the project when you change files and refresh the page. ● IDE support for IntelliJ, Eclipse, Sublime, and more. ● Asset compiler for LESS, CoffeeScript, and more. ● JSON is a first-class citizen.
  • 20. Play! Resources ● http://www.playframework.com/ ● https://github.com/playframework/playframework ● https://groups.google.com/group/play-framework ● http://www.playframework.com/documentation ● http://twitter.com/playframework
  • 22. Topics ● Request Handling – URLs – Controllers – Actions – Responses – HTTP ● Views – Templates – Encoding – Assets ● Forms – Validation – Submission
  • 23. Topics (cont.) ● Database – Evolutions – Connections – Models – Queries ● Build System – Dependencies – Deployment – Testing ● Application Global – Request Handling – Error Handling – Application Hooks ● I18n – Strings – Views – Configuration
  • 24. Topics (cont.) ● Testing – Fake Application – Fake Requests – Fake DB – Patterns
  • 26. Request Handling - Terminology ● Route – Mapping of URL/HTTP Method to an action ● Action – Function that takes a request and returns a result ● Controller – Action generator ● Request – HTTP headers and body ● Result – HTTP status code, headers, and body
  • 27. Request Handling - Exercise ● Create a new home page ● Create a page that redirects to the new home page ● Set content type on home page ● Create a page to set, and a page to get: – Headers – Cookies – Session – Flash ● Create a TODO page ● Use URL parameters and action to send 404
  • 28. SimpleResults ● Ok ● Created ● Accepted ● MovedPermanently ● Found ● SeeOther ● NotModified ● TemporaryRedirect ● BadRequest ● Unauthorized ● Forbidden ● NotFound ● InternalServerError ● ...
  • 29. Routes ● Every route has HTTP method, URL, and action to call. ● URL can include parameters, which are passed to the action. ● These parameters can be validated and converted as part of the matching. ● First matching route wins.
  • 30. Views ● '@' is the magical operator. ● No special functions, it's just embedded Scala code. ● Each view is just a function that can be called from anywhere. ● Views set the content type automatically.
  • 31. Views - Exercise ● Create view for URL parameter page. ● Create view for the home page. ● Create template, use it in the home page view. ● Add links to template ● Display flash messages in layout. ● Use implicit request.
  • 32. Views ● Files are named package/myview.scala.html. ● Views are referenced views.html.package.myview. ● All values are HTML encoded for you. ● Views are not intended to handle big data. ● If broken, play with the whitespace.
  • 33. Forms - Exercise ● Create a contact form. ● Create a login form. On submit, set a fake user id in the session.
  • 34. Forms ● Form.bindFromRequest will use GET and POST variables. ● There are many constraints and data types. Explore to find them.
  • 35. Database - Exercise ● Configure a database connection. ● Create a database evolution for users table. ● Create page and model to register users. ● Update login to check against user list. ● Create page to show current user.
  • 36. Build System ● Reload play after changing dependencies. ● Find dependencies at http://mvnrepository.com/ ● Try a deployment – `play stage` – `./target/start -Dhttp.port=9000` ● To deploy, copy target/start and target/staged to the target system, and run 'start'
  • 37. I18n - Exercise ● Replace all messages in the layout. ● Add language files ● Configure another language ● Try it in the browser
  • 38. Testing - Exercise ● Inspect and modify existing tests. ● Run tests from command line.
  • 39. Time Permitting ● Advanced Request Handling – EssentialAction – RequestHeader – Iteratees – Filters ● Application Global
  • 40. Thank you for your time. Any Questions?
  • 41. Lucid Software Inc ● Building the next generation of collaborative web applications ● VC funded, high growth, profitable ● Graduates from Harvard, MIT, Stanford ● Team has worked at Google, Amazon, Microsoft https://www.lucidchart.com/jobs