Play Framework Essentials

Book description

An intuitive guide to creating easy-to-build scalable web applications using the Play framework

In Detail

Play is a framework to write web applications using Scala or Java. It provides a productive development environment, allowing you to just hit the "refresh" button in your browser to compile your changes and reload the application. Because of its stateless nature, the framework makes it easy to build applications that scale. Play provides a reactive programming model to harness the event-driven HTTP layer.

This book provides a step-by-step walkthrough of how to build a complete web application following best application development practices using Play framework 2. All aspects specific to web-oriented architectures are covered: the HTTP layer, JSON manipulation, HTML templating, asset compression and concatenation, form submission, content negotiation, security, and HTTP streaming. The book will also provide detailed architectural insights into Play framework to give you a better understanding in order to successfully build scalable applications.

What You Will Learn

  • Set up a unified development environment for both the client-side and server-side code
  • Understand the challenges of building a scalable web application and master the solutions provided by Play framework
  • Integrate the framework with existing client-side or server-side technologies such as persistence systems
  • Harness the reactive programming model to process data streams
  • Design robust, maintainable, and testable code
  • Be proficient in manipulating JSON data blobs
  • Deploy your application on a PaaS platform

Publisher resources

Download Example Code

Table of contents

  1. Play Framework Essentials
    1. Table of Contents
    2. Play Framework Essentials
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Building a Web Service
      1. Play – a framework used to write web applications
      2. Bootstrapping a Play application
        1. Play applications' layout
      3. URL routing
        1. Route path parameters
        2. Parameters type coercion
        3. Parameters with fixed values
        4. Query string parameters
        5. Default values of query string parameters
        6. Trying the routes
      4. Building HTTP responses
        1. Serializing application data in JSON
      5. Reading JSON requests
        1. Validating JSON data
        2. Handling optional values and recursive types
      6. Summary
    9. 2. Persisting Data and Testing
      1. Testing your web service
        1. Writing and running tests
        2. Testing the HTTP layer
          1. Using the reverse router to generate URLs
          2. Running a fake Play application
          3. Effectively writing HTTP tests
      2. Persisting data
        1. Using a relational database
          1. Getting a reference to the currently running application
        2. Using a database management library
          1. Using Slick in Scala
          2. Using JPA in Java
        3. Integrating with other persistence technologies
        4. Populating the database with fixtures
          1. The application's Global object
        5. Managing database schema evolutions
      3. Using an in-memory database for tests
      4. Summary
    10. 3. Turning a Web Service into a Web Application
      1. Delta between a web service and a web application
      2. Using the template engine to build web pages
        1. Inserting dynamic values
        2. Looping and branching
        3. Reusing document fragments
        5. Import statements
      3. Generating HTML forms
        1. Repeated and nested fields
      4. Reading and validating HTML form data
        1. Handling the HTML form submission
        2. Validating the HTML form data
          1. The Scala form validation API
          2. The Java form validation API
          3. Optional and mandatory fields
        3. Sharing JSON validation and HTML form validation rules
      5. Handling content negotiation
      6. Putting things together
      7. Writing web user interface tests
      8. Summary
    11. 4. Integrating with Client-side Technologies
      1. Philosophy of Play regarding client-side technologies
      2. Serving static assets
        1. Sprinkling some JavaScript and CSS
      3. Using the JavaScript reverse router
      4. Managing assets from the build system
        1. Producing web assets
        2. Pipelining web assets' transformations
          1. Concatenating and minifying JavaScript files
          2. Gzipping assets
          3. Fingerprinting assets
        3. Managing JavaScript dependencies
        4. Running JavaScript tests
      5. Summary
    12. 5. Reactively Handling Long-running Requests
      1. Play application's execution model
      2. Scaling up your server
      3. Embracing non-blocking APIs
      4. Managing execution contexts
      5. Writing incremental computations using iteratees
      6. Streaming results using enumerators
      7. Manipulating data streams by combining iteratees, enumerators, and enumeratees
        1. Unidirectional streaming with server-sent events
          1. Preparing the ground
          2. Transforming streams of data using enumeratees
          3. Implementing a publish/subscribe system using Akka
        2. Bidirectional streaming with WebSockets
      8. Controlling the data flow
      9. Summary
    13. 6. Leveraging the Play Stack – Security, Internationalization, Cache, and the HTTP Client
      1. Handling security concerns
        1. Authentication
        2. Cross-site scripting
        3. Cross-site request forgery
          1. HTTP request filters
          2. Using the CSRF filter
        4. Enabling HTTPS
      2. Saving computation time using cache
      3. Serving content in several languages
      4. Calling remote web services
        1. Background – the OAuth 2.0 protocol
        2. Integrating your application with your preferred social network
        3. Implementing the OAuth client
        4. Calling the HTTP API of your preferred social network
      5. Summary
    14. 7. Scaling Your Codebase and Deploying Your Application
      1. Making an action's logic reusable and composable with action builders
        1. Capturing the logic of actions that use blocking APIs
        2. Capturing the logic of actions that require authentication
        3. Combining action builders
      2. Modularizing your code
        1. Applying the inversion of control principle
          1. Using dynamic calls in route definitions
          2. Setting up a dependency injection system
          3. Making your code injectable
        2. Mocking components
        3. Splitting your code into several artifacts
        4. Splitting your controller layer into several artifacts
      3. Application deployment
        1. Deploying to your dedicated infrastructure
        2. Deploying to the cloud
        3. Handling per environment configuration
          1. Overriding configuration settings using Java system properties
          2. Using different configuration files
      4. Summary
    15. Index

Product information

  • Title: Play Framework Essentials
  • Author(s):
  • Release date: September 2014
  • Publisher(s): Packt Publishing
  • ISBN: 9781783982400