Book Image

Learning Play! Framework 2

By : Andy Petrella
Book Image

Learning Play! Framework 2

By: Andy Petrella

Overview of this book

<p>The Learning Play! Framework 2 has been created for web developers that are building web applications. The core idea is to focus on the HTTP features and to enable them through a simplification lens. Building a web application no longer requires a configuration phase, an environment setup, or a long development lifecycle - it's integrated!<br /><br />Learning Play! Framework 2 will enable any web developers to create amazing web applications taking advantage of the coolest features. It's the fastest way to dive into Play!, focusing on the capabilities by using them in a sample application. Although essentially Java based code, a Scala version is presented as well – giving an opportunity to see some Scala in action.<br /><br />After setting up the machine and learning some Scala, you will construct an application which builds from static to dynamic, before introducing a database. <br /><br />Then we'll focus on how data can be consumed and rendered in several ways. This will enable some real time communication through WebSocket and Server-Sent Event – on both server and client sides.</p> <p>The book will end with testing and deployment, which completes any web development project.</p>
Table of Contents (20 chapters)
Learning Play! Framework 2
Credits
About the Author
Acknowledgement
About the Reviewers
www.packtpub.com
Preface
Materials
Index

Preface

This book not only provides you with the opportunity to discover all the basics of Play! Framework 2, but also gives you an insight into its advanced features. This new version of Play! Framework has inherited a lot of features from the previous versions, but it has also learned from them. Thus, it comes with fresh thoughts, a clear vision, and amazing new APIs.

The book will focus on what kind of applications can be built using Play! Framework 2, and what kind of technologies can be used easily with it. In order to demonstrate how it can be easy and fast, we'll build a full application from scratch, integrating as many functionalities as will be needed by any modern web application.

Given that Play! Framework 2 can be used with both Java and Scala, you'll be introduced to the Scala programming language. However, most of the examples are in Java.

What this book covers

Chapter 1, Getting Started with Play! Framework 2, introduces readers to Play! Framework 2 and helps them discover how easy it is to bootstrap your development environment and take a fast track to creating your first application.

Chapter 2, Scala – Taking the First Step, covers just enough of Scala so as to enable you to create advanced Scala templates.

Chapter 3, Templating Easily with Scala, keeps you in touch with the Scala programming language while creating server-side templates. We'll see how to produce views for content and how to combine them. From this chapter, we will start making the application that we will build along with the book.

Chapter 4, Handling Data on the Server Side, explains how to create data on the server side, how to add constraints to them, and then how to generate views on them, while keeping in mind that a web application, especially a CRUD one, mainly deals with data on both server and client sides. By the end of this chapter, you'll be able to create a flow between the browser and the database.

Chapter 5, Dealing with Content, covers how easy it will be to manage different representations of data. We'll introduce how streams are handled by Play! Framework 2, using body parsers. We'll also take the opportunity to use JSON to share our data between the client and the server sides. Also, we'll see how to create an Atom feed of the same data.

Chapter 6, Moving to Real-time Web Applications, demonstrates how to achieve more powerful features (required by any modern web applications) to deal with data in a real-time fashion, using the APIs provided with Play! Framework 2. You'll build an end-to-end workflow using CoffeeScript in the browser to consume events produced on a WebSocket by the server.

Chapter 7, Web Services – At Your Disposal, covers the WS API that Play! Framework 2 includes. This API will leave us consuming or producing content to a different application, using whatever representation of the data we're used to. To illustrate such a use case, we'll connect to Twitter's end points to consume tweets and show them in our application.

Chapter 8, Smashing All Test Layers, gives an overview of all test layers that can be covered using the test features provided by Play! Framework 2. Being a full-stack framework, Play! Framework 2 not only includes binding with testing frameworks, but also mockups for the whole server. By the end of this chapter, you'll be able to test the server-side code and also the user interface using Selenium. The chapter is also the only one that is Scala- and not Java-oriented.

Chapter 9, Code Once, Deploy Everywhere, explains how a Play! Framework application can be used in a continuous integration tool, and how to put it in production by following the continuous-deployment philosophy. You'll also be introduced to the Typesafe console that can help us monitor applications at runtime.

Appendix A, Introducing Play! Framework 2, gives you a deeper insight into the underlying concepts on which Play! Framework is built. We'll see why it is so awesome and what its differences are with the first version. It's also a good place to start, where an overview of the features of Play! Framework 2 can be grasped at once.

Appendix B, Moving Forward, keeps you moving forward with all the very advanced features of Play! Framework 2 that we had to leave aside for a while. You'll also see that the Play! community is expanding very fast and that a lot of helpful plugins are already available.

Appendix C, Materials, gives information about the publicly available sources on GitHub.

What you need for this book

As Play! Framework 2 is meant to be "full stack" and completely integrated, the good news is that there are no specific requirements for you or your environment to start creating new web applications.

However, I could give you some common advice, for example, having random hardware is good enough, but having an SSD can be really helpful. This is because we'll be in the JVM world, where compilations will be needed and thus filesystem access can be intense. So just bring your machine and your preferred text editor (or IDE) and go ahead.

Who this book is for

The book does not focus on algorithms or model patterns at all. Instead, this book is for web developers. The reader must be interested with the Web world without (especially) being an expert in making web applications. However, a good understanding of third-tier applications over HTTP will be a plus.

The skills required are as few as the prerequisite knowledge required is less. The reader should be familiar with object-oriented languages and have some notion of client-side technologies such as JavaScript, CSS, and HTML.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Now that your machine is prepared, we can create our first project using the play command."

A block of code is set as follows:

Long chatId = Long.parseLong(queryString.get("chatid")[0]);
Map<String,String[]> queryString = request().queryString();

Any command-line input or output is written as follows:

$> cd play-jbook
$> play

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "In the new window, click on the Environment Variables... button."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.