Search code examples
scalaplayframeworkhttp2

How to send HTTP 2.0 request in play framework(scala)


Backend running under play framework(v. 2.6.5 scala) must communicate with Apple Push Notificaton Service (APNs) . APNs requires using HTTP/2, and so i tried to find any way to implement such communication, but to my surprise i didn`t find any http scala clients, supporting http v 2.0. Is there any way to realize such communication without going out of the framework? Thanks!


Solution

  • Play Framework with a version prior to 2.6 does not support HTTP 2.0, but, Play Framework 2.6 is based on Akka-Http and has experimental support for HTTP 2.0. This feature is labeled "experimental" because the API may change in the future, and it has not been thoroughly tested in the wild.

    To add support for HTTP/2, add the PlayAkkaHttp2Support plugin. You can do this in an enablePlugins:

    lazy val root = (project in file("."))
      .enablePlugins(PlayScala, PlayAkkaHttp2Support)
    

    If you consider alternatives take a look at:

    1. Jetty has a capability to use HTTP 2.0
    2. Netty also supports HTTP 2.0

    Check this list of known implementations of HTTP 2.0.