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

It's alive and not empty!


In the earlier sections we saw how to create a project, import it into our development environment, and we even learned how to attach new libraries to it.

Now it's time to look at what has been created so far. As we've chosen not to create an empty project (which was the third option proposed by the play new command), we already have a certain amount of things available for our perusal.

Rather than looking at the files, we are going to run the application using a play command to compile everything and start a server that will run our application.

To do this, enter the play! console and type run:



As we can see, the console tells us that it has started the application and an HTTP server is available on port 9000.

The next logical step is to open our browser and request this brand new server by going to the URL http://localhost:9000/.

Once done, our page should look like the following screenshot:

What is being shown is the default welcome web page that Play! 2 has made available for us.

As shown in the previous screenshot, this page already contains a lot of information, essentially the basics (that we'll cover next) and some help about the environment (which we've just covered).

Recall that when we installed Play!, the Play! Framework 2 installation directory contained a documentation folder. Now that we have an application running, we'll see that this documentation wasn't there for no reason.

If we pay more attention to the welcome page, there is a Browse menu on the right side of the page. This menu has two items. Let's have a quick overview of them now.

The first item, Local documentation, is a reference to the manual folder of our installation. So we can access the current Play! version's documentation directly from our application (at development time only, not in production).

The second item is the API and is discussed in the next section.

Browsing the Java API

Before entering into any details, we must have noted that the menu has the word Java in its name. That's because Play! has detected (we'll see how later) that we're running a Java application.

On entering this menu, we'll see the following web page:



As expected, we obtained the well-known Javadoc website. We won't cover the API here, but the good thing to note is that we'll always have direct access to it without having to generate it, browse the Web to find it, and so on.

Note

This kind of website is also available for the Scala version, but it has a slightly different presentation.