SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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.0Oscar Renalias
 
Concurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka wayYardena Meymann
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to LaravelEli Wheaton
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with LumenKit Brennan
 
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 WorldTareque Hossain
 
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!Chris Roberts
 
20171108 PDN HOL React Basics
20171108 PDN HOL React Basics20171108 PDN HOL React Basics
20171108 PDN HOL React BasicsRich Ross
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMatt Butcher
 
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 4Darwin Biler
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to LaravelVin Lim
 
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 OracleRaimonds Simanovskis
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introductionSimon Funk
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Laravel Webcon 2015
Laravel Webcon 2015Laravel Webcon 2015
Laravel Webcon 2015Tim Bracken
 
Java Enterprise Edition Concurrency Misconceptions
Java Enterprise Edition Concurrency Misconceptions Java Enterprise Edition Concurrency Misconceptions
Java Enterprise Edition Concurrency Misconceptions Haim Yadid
 

Tendances (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
 

En vedette

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 ScalaYevgeniy Brikman
 
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
 
Play Template Engine Based On Scala
Play Template Engine Based On ScalaPlay Template Engine Based On Scala
Play Template Engine Based On ScalaKnoldus Inc.
 
Designing Reactive Systems with Akka
Designing Reactive Systems with AkkaDesigning Reactive Systems with Akka
Designing Reactive Systems with AkkaThomas Lockney
 
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 2011Matt Raible
 
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.Eng Chrispinus Onyancha
 
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 JVMManuel Bernhardt
 
Введение в Akka
Введение в AkkaВведение в Akka
Введение в AkkaZheka Kozlov
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysManuel Bernhardt
 
Spring Scala : 스프링이 스칼라를 만났을 때
Spring Scala : 스프링이 스칼라를 만났을 때Spring Scala : 스프링이 스칼라를 만났을 때
Spring Scala : 스프링이 스칼라를 만났을 때JeongHun Byeon
 
Dependency injection in scala
Dependency injection in scalaDependency injection in scala
Dependency injection in scalaMichal Bigos
 
Язык программирования Scala / Владимир Успенский (TCS Bank)
Язык программирования Scala / Владимир Успенский (TCS Bank)Язык программирования Scala / Владимир Успенский (TCS Bank)
Язык программирования Scala / Владимир Успенский (TCS Bank)Ontico
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play appsYevgeniy Brikman
 

En vedette (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
 

Similaire à Your First Scala Web Application using Play 2.1

Moodle Development Best Pracitces
Moodle Development Best PracitcesMoodle Development Best Pracitces
Moodle Development Best PracitcesJustin Filip
 
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 KrausWomen in Technology Poland
 
Introduction to rails
Introduction to railsIntroduction to rails
Introduction to railsGo Asgard
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusBoldRadius Solutions
 
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 2018Holden Karau
 
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 BeginnerHirokazu Tokuno
 
Javascript Update May 2013
Javascript Update May 2013Javascript Update May 2013
Javascript Update May 2013Ramesh Nair
 
Deploying Perl apps on dotCloud
Deploying Perl apps on dotCloudDeploying Perl apps on dotCloud
Deploying Perl apps on dotClouddaoswald
 
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 XitrumNgoc Dao
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
Angular basicschat
Angular basicschatAngular basicschat
Angular basicschatYu Jin
 
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 InterfacesJumping Bean
 
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 serverEugene Yokota
 
Java on Google App engine
Java on Google App engineJava on Google App engine
Java on Google App engineMichael Parker
 
Android training day 4
Android training day 4Android training day 4
Android training day 4Vivek Bhusal
 
PHP BASIC PRESENTATION
PHP BASIC PRESENTATIONPHP BASIC PRESENTATION
PHP BASIC PRESENTATIONkrutitrivedi
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsOWASP Kyiv
 

Similaire à 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
 

Plus de Matthew Barlocker

Plus 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
 

Dernier

Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
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
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
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
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
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
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 

Dernier (20)

Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
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.
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
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
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
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
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 

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