The Play Framework is a Java web framework that disposes of much of the traditional Java dogma and strives to create a developer experience similar to that of more established frameworks in other languages such as Rails and Django. Gone are the routine getters and setters, replaced by public static fields. Similarly, controller methods are implemented as public static methods. Once a seasoned Java developer has gotten over these shocking design decisions and actually written an application or two with Play, the Play Framework Cookbook by Alexander Reelsen is a good next step to learning the full depth of the framework.
It took me about 50 pages to get into the Play Framework Cookbook. The stated goal of the book is to pick up where the beginner’s documentation leaves off. Having already written a couple applications using Play, I was hoping the book would jump right into some nice advanced topics that I wasn’t familiar with. Instead, the first chapter (Basics of the Play Framework) dealt with exactly the beginner issues that are better handled with a Getting Started guide. If you’ve spent much time with the Play framework, you’ll probably be best served by jumping ahead to Chapter 2 (Using Controllers). Here, the author makes an emphasis on keeping your controllers lean by generous use of helper classes and methods. The renderPDF and renderRSS methods presented are good examples of this.
The similar concept that your application should remain lean and functionality should be extracted into modules is introduced in Chapter 3 (Leveraging Modules). The author shows a nice selection of built-in and downloadable modules that can be used to clean up your code (dependency injection), lock down your application (security), and interact with other databases (MongoDB). This would have been a nice place to jump right into writing your own modules, but first there’s the small interlude that is Chapter 4 (Creating and Using APIs). This chapter included a nice example for creating a custom tag to display charts from the Google Chart API, but it still seemed out of place.
Chapters 5 (Introduction to Writing Modules) and 6 (Practical Module Examples) provide a solid overview of the module system and how it can be used. Even more important, it discusses the limitations of Play modules and how they can be avoided. The author also gets his hands dirty with topic of bytecode enhancement, a technique that Play uses to provide the optimum developer experience. Writing the code to provide that experience (non-type-checked code in quotes, eek!) is something I’d like to avoid, but at least I know now how Play does it. Other examples include relevant topics such as indexing with Solr and interacting with ActiveMQ.
The final chapter (Running in Production) addresses some issues that pop up when moving from developer machine to the data center. A number of recipes demonstrate deployment with popular web servers (Apache, Nginx, Lighttpd) if you don’t want to use the built-in Play server in production. Integration with the Jenkens and Calimoucho continuous integration systems is also discussed in this chapter, although I think these topics would have been better suited to a separate chapter focusing on testing. Rounding out the production chapter are a number of topics related to monitoring and logging.
Overall, I think the Play Framework Cookbook would be a reasonable purchase for someone who’s written a couple smaller applications using Play and is looking towards something larger and more complex. The suggestions for keeping your classes and application lean will surely be useful. The second chapter is available as a sample from the publisher’s website.
Disclosure: I was provided with an eBook copy of the Play Framework Cookbook by Packt Publishing for the purposes of this review.