Play uses the Akka HTTP server backend to implement HTTP requests and responses using Akka Streams over the network. Akka HTTP implements a full server stack for HTTP, including full HTTPS support, and has support for HTTP/2.

The Akka HTTP server backend is the default in Play. You can also use the Netty backend if you choose.

Play’s server backend automatically converts of an Akka HttpRequest into a Play HTTP request, so that details of the implementation are under the hood. Play handles all the routing and application logic surrounding the server backend, while still providing the power and reliability of Akka-HTTP for processing requests.

Like the rest of Play, Akka HTTP is non-blocking. This means that it uses a small number of threads which it keeps loaded with work at all times.

This poses a problem when working with blocking APIs such as JDBC or HTTPURLConnection, which cause a thread to wait until data has been returned from a remote system.

Please configure any work with blocking APIs off the main rendering thread, using a Future or CompletionStage configured with a CustomExecutionContext and using a custom thread pool defined in ThreadPools. See JavaAsync and ScalaAsync for more details.

Play’s Akka HTTP server also supports HTTP/2. This feature is labeled “experimental” because the API may change in the future, and it has not been thoroughly tested in the wild. However, if you’d like to help Play improve please do test out HTTP/2 support and give us feedback about your experience.

You also should Configure HTTPS on your server before enabling HTTP/2. In general, browsers require TLS to work with HTTP/2, and Play’s Akka HTTP server uses ALPN (a TLS extension) to negotiate the protocol with clients that support it.

To add support for HTTP/2, add the PlayAkkaHttp2Support plugin. You can do this in an enablePlugins call for your project in build.sbt, for example:

It will add the play-akka-http2-support module, which provides extra configuration for HTTP/2 and depends on the akka-http2-support module. By default HTTP/2 is enabled. It can be disabled by passing the http2.enabled system property, e.g. play "start -Dhttp2.enabled=no".

Configures the Jetty ALPN agent as a Java agent using sbt-javaagent, and automatically adds the -javaagent argument for start, stage and dist tasks (i.e. production mode). This adds ALPN support to the JDK, allowing Akka HTTP to negotiate the protocol with the client. It does not configure for run mode. In JDK 9 this will not be an issue, since ALPN support is provided by default.

If for some reason you have both the Akka HTTP and the Netty server JARs on your classpath, then Play won’t be able to predictably choose a server backend. You’ll need to manually select the Akka HTTP server. This can be done by explicitly overriding the play.server.provider configuration option and setting it to a value of play.core.server.AkkaHttpServerProvider.

The play.server.provider configuration setting can be set in the same way as other configuration options. Different methods of setting configuration are described in the configuration file documentation. Several examples of enabling the Akka HTTP server backend are shown below.

The recommended way to do this is to add the setting to two places. First, to enable Akka HTTP for the sbt run task, add the following to your build.sbt: