Book Image

Mastering play framework for scala

By : Shiti Saxena
Book Image

Mastering play framework for scala

By: Shiti Saxena

Overview of this book

Table of Contents (21 chapters)
Mastering Play Framework for Scala
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with Play
Index

Preface

The Play Framework is an open source web application framework that is written in Java and Scala. It follows the Model-View-Controller architectural pattern.

It enables the user to use Scala for application development, keeping key properties and features of the Play Framework intact. This results in faster and scalable web apps. Also, it uses a more functional and "Scala idiomatic" style of programming, without sacrificing simplicity and developer friendliness.

This book will provide advanced information on developing Scala web applications using the Play Framework. This will help Scala web developers master Play 2.0 and use it for pro-Scala web app development.

What this book covers

Chapter 1, Getting Started with Play, explains how to build simple applications using the Play Framework. We also explore the project structure so that you can understand how the framework plugs in the required settings through a build file.

Chapter 2, Defining Actions, explains how we can define an application-specific action with default parsers and results, and also with custom parsers and results.

Chapter 3, Building Routes, is where we see how essential routing is in a Play application. Apart from this, we also check out various default methods that Play provides for simplifying the process of routing.

Chapter 4, Exploring Views, explains how to create views using Twirl and the various other helper methods provided by Play. In this chapter, you also learn how you can support multiple languages in your Play application using the built-in i18n API.

Chapter 5, Working with Data, demonstrates different ways of causing application data to persist in an application that we build using the Play Framework. In addition to this, you also get to understand how the Play Cache API can be used and how it works.

Chapter 6, Reactive Data Streams, discusses the concepts of Iteratee, Enumerator, and Enumeratee and how they can be implemented in the Play Framework and used internally.

Chapter 7, Playing with Globals, gives an insight into the features provided for a Play application through the global plugin. We also discuss hooks for the request-response life cycle, using which we can intercept requests and responses and modify them if required.

Chapter 8, WebSockets and Actors, briefly covers the Actor Model and the usage of Akka Actors in an application. We also define a WebSocket connection in a Play application with various constraints and requirements, using different approaches.

Chapter 9, Testing, shows you how a Play application can be tested using Specs2 and ScalaTest. We go through the different helper methods available for simplifying testing of a Play application.

Chapter 10, Debugging and Logging, is where we configure the debugging of a Play application in the IDE. In this chapter, you get to learn how to start a Play application in the Scala console. This chapter also places emphasis on the logging API provided by the Play Framework and the methods of customizing the log format.

Chapter 11, Web Services and Authentication, explains the WS (WebService) plugin and the API exposed through it. We also access users' data from the service providers using OpenID and OAuth 1.0a.

Chapter 12, Play in Production, explains how to deploy a Play application on production. While deploying the application, we also check the different packaging options (RPM, Debian, ZIP, Windows, and so on) available by default.

Chapter 13, Writing Play Plugins, gives an explanation of all plugins, with their declaration, definition, and best practices.

What you need for this book

Before starting with this book, make sure that you have all of the necessary software installed. The prerequisites for this book are as follows:

Who this book is for

This book is intended for those developers who are keen on mastering the internal working of Play Framework to effectively build and deploy web-related apps. It is assumed that you have a basic understanding of the core app development techniques.

Conventions

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

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Update the index template so that each <li> element has a button, clicking on which results in a delete request to the server."

A block of code is set as follows:

def running[T](app: Application)(block: => T): T = {
    synchronized {
      try {
        Play.start(app)
        block
      } finally {
        Play.stop()
      }
    }
  }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

class WebSocketChannel(out: ActorRef)
  extends Actor with ActorLogging {

  val backend = Akka.system.actorOf(DBActor.props)
  def receive: Actor.Receive = {
    case jsRequest: JsValue =>
      backend ! convertJsonToMsg(jsRequest)
    case x:DBResponse =>
      out ! x.toJson
  }
}

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

> run
[info] Compiling 1 Scala source to /AkkaActorDemo/target/scala-2.10/classes...
[info] Running com.demo.Main
?od u od woH ,olleH
ekops ew ecnis gnoL neeB
Sorry, didn't quite understand that I can only process a String.

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "The form is not submitted when you click on Submit, and no errors are displayed using globalErrors."

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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail us at , and mention the book's title in 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 at 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 from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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 could 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.