SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
Play Framework
The big picture
The Big Picture (contd.)
1. Follows Async model of request response
○ Jetty
○ NIO
2. Not one thread per request
3. MVC design pattern separates application’s logic and data from the user
interface’s
4. Brings in Scala type safety to good use
5. Great DX
○ Errors are shown on the browser
○ Auto reload, no messy build and redeployment
The Big Picture (contd.)
How do you create one?
Use SBT
sbt new playframework/play-scala-seed.g8
And you get this common play project structure
Different parts of Play Framework => =>
1. The Routes file
GET / controllers.Application.index
POST /product controllers.Products.addProduct
GET /products controllers.Products.list
GET /product/:id controllers.Products.getProductById(id: Long)
GET /product/byName controllers.Products.getProductByName(name: String)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
2. The Controller
● Extend your class with play.mvc.Controller
● Write methods to handle calls in the routes file
● The Action class
a. final def apply(block: => Result): Action[AnyContent]
b. final def async(block: => Future[Result]): Action[AnyContent]
c. final def async[A](bodyParser: BodyParser[A])(block: R[A] => Future[Result]):
Action[A]
● controllers, actions, requests, and responses as Scala traits in the
play.api.mvc package - controller layer API
● MVC API mixes the HTTP concepts (request, response), with MVC concepts
such as controllers and actions.
2. The Controller (contd.) => Important Classes/Traits
Corresponding to HTTP concepts
play.api.mvc.Cookie — An HTTP cookie: a small amount of data stored on the client and
sent with subsequent requests
play.api.mvc.Request — An HTTP request: HTTP method, URL, headers, body, and
cookies
play.api.mvc.RequestHeader — Request metadata: a name-value pair
play.api.mvc.Response — An HTTP response, with headers and a body; wraps a Play
Result
play.api.mvc.ResponseHeader — Response metadata: a name-value pair
2. The Controller (contd.) => Important Classes/Traits
Corresponding to MVC and extras
play.api.mvc.Action — A function that processes a client Request and returns a Result
play.api.mvc.Result — The result of calling an Action to process a Request, used to generate an
HTTP response
play.api.mvc.Call — An HTTP request: the combination of an HTTP method and a URL
play.api.mvc.Content — An HTTP response body with a particular content type
play.api.mvc.Controller — A generator for Action functions
play.api.mvc.Session — A set of string keys and values, stored in an HTTP cookie
3. The View/Template
1. Type safe template engine
2. HTML 5 mark up with Scala
3. Easy to compose
@import services.ProductsService.Product
@(products: List[Product])
@main("Demo Product Application") {
<dl class="products">
@for(product <- products) {
<dt>@product.name</dt>
<dd>@product.description</dd>
}
</dl>
}
4. Play JSON
1. Easy to write formats for models
2. Uses macro to generate JSON reads and writes
○ case class Product(id: Long, name: String, description: String)
○ implicit val productFormat = Json.format[Product]
3. Built on top of Jackson
5. Public Assets
GET /assets/*file controllers.Assets.at(path="/public", file)
1. Treated as any other route so easier to use the reverse route without using the
actual path in all the templates
2. *file part matches anything including the /
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
1. automatically manages ETag HTTP Headers.
2. When a web browser makes a request specifying this Etag then the server can
respond with 304 NotModified.
6. Internationalization with Messages
conf/messages—Default messages for all languages, for messages not localized
for a particular language
conf/messages.es—Spanish (which is called Español in Spanish)
conf/messages.fr—French (Français in French)
conf/messages.nl—Dutch (Nederlands in Dutch)
=> Inject MessagesApi and call the apply method with the key and varargs as
message arguments and you are done!
Request/Response Flow
play.api.mvc.Result — The result of calling an Action to process a Request, used to generate an
HTTP response
Resources
1. Play’s official docs - https://www.playframework.com/documentation
2. Play For Scala (Book) - https://www.manning.com/books/play-for-scala
3. Talks -
a. The Play Framework at LinkedIn: Productivity and Performance at Scale -
https://www.youtube.com/watch?v=8z3h4Uv9YbE
b. James Ward: Modern Play Apps with Play Framework -
https://www.youtube.com/watch?v=Dfek3hIVRtw
Thank You!

Mais conteúdo relacionado

Mais procurados (14)

Inner core of Ajax
Inner core of Ajax Inner core of Ajax
Inner core of Ajax
 
How to Recover Outlook PST File
How to Recover Outlook PST FileHow to Recover Outlook PST File
How to Recover Outlook PST File
 
2310 b 12
2310 b 122310 b 12
2310 b 12
 
SQLite 3
SQLite 3SQLite 3
SQLite 3
 
Intro webapps
Intro webappsIntro webapps
Intro webapps
 
App D
App DApp D
App D
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
 
Ajax and xml
Ajax and xmlAjax and xml
Ajax and xml
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
Power shell basics day 7
Power shell basics day 7Power shell basics day 7
Power shell basics day 7
 
Sqlite
SqliteSqlite
Sqlite
 
Asp db
Asp dbAsp db
Asp db
 
Query transport problems
Query transport problemsQuery transport problems
Query transport problems
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
 

Semelhante a Play framework

nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
WalaSidhom1
 

Semelhante a Play framework (20)

Active Server Page - ( ASP )
Active Server Page - ( ASP )Active Server Page - ( ASP )
Active Server Page - ( ASP )
 
07 response-headers
07 response-headers07 response-headers
07 response-headers
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Asp.net By Durgesh Singh
Asp.net By Durgesh SinghAsp.net By Durgesh Singh
Asp.net By Durgesh Singh
 
asp_intro.pptx
asp_intro.pptxasp_intro.pptx
asp_intro.pptx
 
Meet with Meteor
Meet with MeteorMeet with Meteor
Meet with Meteor
 
Ibm
IbmIbm
Ibm
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Synopsis
SynopsisSynopsis
Synopsis
 
12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat12 core technologies you should learn, love, and hate to be a 'real' technocrat
12 core technologies you should learn, love, and hate to be a 'real' technocrat
 
State management servlet
State management servletState management servlet
State management servlet
 
Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)Having Fun Building Web Applications (Day 2 slides)
Having Fun Building Web Applications (Day 2 slides)
 
Internet Explorer 8
Internet Explorer 8Internet Explorer 8
Internet Explorer 8
 
Web storage
Web storage Web storage
Web storage
 
Introduction to Node JS1.pdf
Introduction to Node JS1.pdfIntroduction to Node JS1.pdf
Introduction to Node JS1.pdf
 
flask.pptx
flask.pptxflask.pptx
flask.pptx
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
Wikilims Road4
Wikilims Road4Wikilims Road4
Wikilims Road4
 
Cloud Computing in Systems Programming Curriculum
Cloud Computing in Systems Programming CurriculumCloud Computing in Systems Programming Curriculum
Cloud Computing in Systems Programming Curriculum
 

Último

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Último (20)

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

Play framework

  • 3. The Big Picture (contd.) 1. Follows Async model of request response ○ Jetty ○ NIO 2. Not one thread per request 3. MVC design pattern separates application’s logic and data from the user interface’s 4. Brings in Scala type safety to good use 5. Great DX ○ Errors are shown on the browser ○ Auto reload, no messy build and redeployment
  • 4. The Big Picture (contd.)
  • 5. How do you create one? Use SBT sbt new playframework/play-scala-seed.g8 And you get this common play project structure
  • 6. Different parts of Play Framework => =>
  • 7. 1. The Routes file GET / controllers.Application.index POST /product controllers.Products.addProduct GET /products controllers.Products.list GET /product/:id controllers.Products.getProductById(id: Long) GET /product/byName controllers.Products.getProductByName(name: String) # Map static resources from the /public folder to the /assets URL path GET /assets/*file controllers.Assets.at(path="/public", file)
  • 8. 2. The Controller ● Extend your class with play.mvc.Controller ● Write methods to handle calls in the routes file ● The Action class a. final def apply(block: => Result): Action[AnyContent] b. final def async(block: => Future[Result]): Action[AnyContent] c. final def async[A](bodyParser: BodyParser[A])(block: R[A] => Future[Result]): Action[A] ● controllers, actions, requests, and responses as Scala traits in the play.api.mvc package - controller layer API ● MVC API mixes the HTTP concepts (request, response), with MVC concepts such as controllers and actions.
  • 9. 2. The Controller (contd.) => Important Classes/Traits Corresponding to HTTP concepts play.api.mvc.Cookie — An HTTP cookie: a small amount of data stored on the client and sent with subsequent requests play.api.mvc.Request — An HTTP request: HTTP method, URL, headers, body, and cookies play.api.mvc.RequestHeader — Request metadata: a name-value pair play.api.mvc.Response — An HTTP response, with headers and a body; wraps a Play Result play.api.mvc.ResponseHeader — Response metadata: a name-value pair
  • 10. 2. The Controller (contd.) => Important Classes/Traits Corresponding to MVC and extras play.api.mvc.Action — A function that processes a client Request and returns a Result play.api.mvc.Result — The result of calling an Action to process a Request, used to generate an HTTP response play.api.mvc.Call — An HTTP request: the combination of an HTTP method and a URL play.api.mvc.Content — An HTTP response body with a particular content type play.api.mvc.Controller — A generator for Action functions play.api.mvc.Session — A set of string keys and values, stored in an HTTP cookie
  • 11. 3. The View/Template 1. Type safe template engine 2. HTML 5 mark up with Scala 3. Easy to compose @import services.ProductsService.Product @(products: List[Product]) @main("Demo Product Application") { <dl class="products"> @for(product <- products) { <dt>@product.name</dt> <dd>@product.description</dd> } </dl> }
  • 12. 4. Play JSON 1. Easy to write formats for models 2. Uses macro to generate JSON reads and writes ○ case class Product(id: Long, name: String, description: String) ○ implicit val productFormat = Json.format[Product] 3. Built on top of Jackson
  • 13. 5. Public Assets GET /assets/*file controllers.Assets.at(path="/public", file) 1. Treated as any other route so easier to use the reverse route without using the actual path in all the templates 2. *file part matches anything including the / GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset) 1. automatically manages ETag HTTP Headers. 2. When a web browser makes a request specifying this Etag then the server can respond with 304 NotModified.
  • 14. 6. Internationalization with Messages conf/messages—Default messages for all languages, for messages not localized for a particular language conf/messages.es—Spanish (which is called Español in Spanish) conf/messages.fr—French (Français in French) conf/messages.nl—Dutch (Nederlands in Dutch) => Inject MessagesApi and call the apply method with the key and varargs as message arguments and you are done!
  • 15. Request/Response Flow play.api.mvc.Result — The result of calling an Action to process a Request, used to generate an HTTP response
  • 16. Resources 1. Play’s official docs - https://www.playframework.com/documentation 2. Play For Scala (Book) - https://www.manning.com/books/play-for-scala 3. Talks - a. The Play Framework at LinkedIn: Productivity and Performance at Scale - https://www.youtube.com/watch?v=8z3h4Uv9YbE b. James Ward: Modern Play Apps with Play Framework - https://www.youtube.com/watch?v=Dfek3hIVRtw