Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Play Framework essentials
  • Table Of Contents Toc
Play Framework essentials

Play Framework essentials

By : Julien Richard-Foy
3.6 (8)
close
close
Play Framework essentials

Play Framework essentials

3.6 (8)
By: Julien Richard-Foy

Overview of this book

This book targets Java and Scala developers who already have some experience in web development and who want to master Play framework quickly and efficiently. This book assumes you have a good level of knowledge and understanding of efficient Java and Scala code.
Table of Contents (9 chapters)
close
close
8
Index

Making an action's logic reusable and composable with action builders


This section shows patterns to factor out the common code that is duplicated in your controllers. The resulting action builders can be used to capture transversal concerns such as authentication.

Capturing the logic of actions that use blocking APIs

We saw in Chapter 5, Reactively Handling Long-running Requests, how to specify in which execution context to execute an action communicating with a database using a blocking API based on JDBC. We did this by wrapping the action code in a Future object (a Promise object in Java) and by explicitly specifying which execution context to use to execute them. This resulted in quite bloated code:

import my.execution.context
val myAction = Action.async {
  Future {
    // the action's code actually starts only here!
  }
}

The Java equivalent was the following:

public static Promise<Result> myAction() {
  return Promise.promise(
    () -> {
      // the action's code actually starts...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Play Framework essentials
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon