Play in Practice. Play Framework: async I/O without the thread pool and callback hell. Under the hood, LinkedIn consists of hundreds of services that can be evolved and scaled independently. That is, all functionality is broken down into separate codebases, deployed on separate hardware, and exposed via well-defined APIs. For example, we may have separate front-end services (e.g. Profile, Skills) that talk to separate back-end services (e.g. profile-backend, skills-backend), which in turn talk to separate data services (e.g. Voldemort or Kafka). In this architecture, our services spend most of their time calling other services and waiting on I/O. Most server technologies rely on a thread pool to handle I/O. Recently, we started using the Play Framework to build our services. However, if you’re not careful with asynchronous code, you may now find yourself in a new kind of hell: deeply nested spaghetti code that jumps all over the place, AKA callback hell (JavaScript, I’m looking at you).
Threaded vs. There are two general approaches: Threaded vs. Threaded vs. Comprehensions. Unveiling Play 2.1 Json API - Part 1 : JsPath & Reads combinators - Mandubian Blog. Addendum: recent API refactoring (modified in the articled) Reads[A] provided Reads[B] has been renamed to Reads[A] keepAnd Reads[B]Reads[A] andThen Reads[B] has been renamed to Reads[A] andKeep Reads[B] In incoming Play2.1 version, a huge re-thinking has been done about JSON API provided by Play2.0.x which provides some great features but is clearly just the tip of the iceberg… Here is a first presentation of those evolutions aimed at unleashing your JSON usage in Play2 and revealing new forms of manipulation of web dataflows from/to external data systems. A usecase of this is manipulating DB structures directly using Json without any class models for document oriented structures such as MongoDB BTW Don’t forget the recent release of new MongoDB async/non-blocking driver ReactiveMongo ;-) Summary of main new features added in Play2.1 Now let’s go in the details ;) Concerning the new Json syntax, I won’t spend time on this, it’s quite explicit and you can try it very easily by yourself.
Authentication for Play Framework Applications. SecureSocial is an authentication module for Play Framework applications that works with services based on OAuth1, OAuth2 and OpenID*. It provides out of the box support for: Twitter (OAuth1) Facebook (OAuth2) GitHub (OAuth2) Google (OAuth2) LinkedIn (OAuth1 and OAuth2) Foursquare (OAuth2) Instagram (OAuth2) VK (OAuth2) XING (OAuth1) Username/Password with signup and reset password functionality. *OpenID and more services are coming soon SecureSocial is written in Scala. However, if you don't use Scala fear not, the module provides APIs in both languages so you can use your preferred one :-). Versions Stable 2.1.3 for Play 2.2.x 2.1.1 for Play 2.1.x 2.0.13 for Play 2.0.6 0.2.6 for Play 1: available via the official Play module repository and under the 1.x branch on GitHub. Snapshots SecureSocial for Play 2.2.x is built from master Note: you can use snapshots to get access to the latest changes but keep in mind that things might break there.
Important. Understanding the Play Filter API - all that jazz. With Play 2.1 hot off the press, there have been a lot of people asking about the new Play filter API. In actual fact, the API is incredibly simple: Essentially, a filter is just a function that takes an action and returns another action. The usual thing that would be done by the filter is wrap the action, invoking it as a delegate.
To then add a filter to your application, you just add it to your Global doFilter method. Easy right? A short introduction to Plays architecture I don't need to go in depth here because I've already provided a link to our architecture documentation, but in short Play's architecture matches the flow of an HTTP request very well. The first thing that arrives when an HTTP request is made is the request header.
What happens next in an HTTP request? The next thing that happens in an HTTP request is that the http response must be sent. All of this is captured in Plays EssentialAction trait: The simpler way The noop filter Handling the request header Handling the body. Play vs. Grails Smackdown. We developed the same app, in similar ways, so let's look at the different layers. Database - Grails Hibernate is the default persistence provider Create models, Hibernate creates the schema for you grails-app/conf/DataSource.groovy Database - Play EBean is the default persistence provider in Java projects Evolutions can be auto-applied Initial evolution sql is auto-created Subsequent changes must be versioned Auto-created schema file is database dependent Play 2 supports multiple datasources (Play 1 does not) conf/evolutions/default/2.sql ALTER TABLE account ADD is_admin boolean; UPDATE account SET is_admin = FALSE; ALTER TABLE account DROP is_admin; Using Heroku Postgres in production rocks!
Postgres 9.1 Dataclips Fork & Follow Multi-Ingres URL Mapping - Grails grails-app/conf/UrlMappings.groovy URL Mapping - Play conf/routes Models - Grails All properties are persisted by default Constraints Mappings with hasMany and belongsTo Override methods for lifecycle events Models - Play Controllers - Grails. Writing an OAuth provider in Play. Using Guice with Play! Framework 2.1 for easy Dependency Injection | 42 Engineering. One of Play! Framework 2.1‘s latest features is the ability to construct controllers, so you can use dependency injection. Briefly, the benefits of using dependency injection is that you will have more modular, extensible, flexible, and testable code.
At FortyTwo, we use Guice (a lightweight DI framework by Google) for many of our system components. I’ll show you how to easily integrate Guice into an example Play! 2.1 Scala project and then show you how this greatly improves your codebase’s flexibility. At its heart, dependency injection allows you to say something like “I’d like a DbConnection instance”, and not have to worry about where it comes from. For this example, we’ll create and test a very simple translation component. First, add Guice and sse-guice to your Build.scala app dependencies: We’ll create a simple Translator trait, which will take an input String, and output its translation.
In a real application, you might implement translate() by calling a 3rd party API. Play! Some Abstract Talk - Playframework: Async, Reactive, Threads, Futures, ExecutionContexts.