Packages

  • package root
    Definition Classes
    root
  • package play

    Play framework.

    Play framework.

    Play

    http://www.playframework.com

    Definition Classes
    root
  • package api

    Contains the public API for Scala developers.

    Contains the public API for Scala developers.

    Access the current Play application
    import play.api.Play.current
    Read configuration
    val poolSize = configuration.getInt("engine.pool.size")
    Use the logger
    Logger.info("Hello!")
    Define a Plugin
    class MyPlugin(app: Application) extends Plugin
    Create adhoc applications (for testing)
    val application = Application(new File("."), this.getClass.getClassloader, None, Play.Mode.DEV)
    Definition Classes
    play
  • package cache

    Contains the Cache access API.

    Contains the Cache access API.

    Definition Classes
    api
  • package controllers
    Definition Classes
    api
  • package data

    Contains data manipulation helpers (typically HTTP form handling)

    Contains data manipulation helpers (typically HTTP form handling)

    import play.api.data._
    import play.api.data.Forms._
    
    val taskForm = Form(
      tuple(
        "name" -> text(minLength = 3),
        "dueDate" -> date("yyyy-MM-dd"),
        "done" -> boolean
      )
    )
    Definition Classes
    api
  • package db

    Contains the JDBC database access API.

    Contains the JDBC database access API.

    Example, retrieving a connection from the 'customers' datasource:

    val conn = db.getConnection("customers")
    Definition Classes
    api
  • package http

    Contains standard HTTP constants.

    Contains standard HTTP constants. For example:

    val text = ContentTypes.TEXT
    val ok = Status.OK
    val accept = HeaderNames.ACCEPT
    Definition Classes
    api
  • package i18n

    Contains the internationalisation API.

    Contains the internationalisation API.

    For example, translating a message:

    val msgString = Messages("items.found", items.size)
    Definition Classes
    api
  • package inject

    Play's runtime dependency injection abstraction.

    Play's runtime dependency injection abstraction.

    Play's runtime dependency injection support is built on JSR-330, which provides a specification for declaring how dependencies get wired to components. JSR-330 however does not address how components are provided to or located by a DI container. Play's API seeks to address this in a DI container agnostic way.

    The reason for providing this abstraction is so that Play, the modules it provides, and third party modules can all express their bindings in a way that is not specific to any one DI container.

    Components are bound in the DI container. Each binding is identified by a BindingKey, which is typically an interface that the component implements, and may be optionally qualified by a JSR-330 qualifier annotation. A binding key is bound to a BindingTarget, which describes how the implementation of the interface that the binding key represents is constructed or provided. Bindings may also be scoped using JSR-330 scope annotations.

    Bindings are provided by instances of Module.

    Out of the box, Play provides an implementation of this abstraction using Guice.

    Definition Classes
    api
    See also

    The Module class for information on how to provide bindings.

  • package internal
    Definition Classes
    api
  • package libs

    Contains various APIs that are useful while developing web applications.

    Contains various APIs that are useful while developing web applications.

    Definition Classes
    api
  • package concurrent
  • package crypto
  • package functional
  • package jcache
  • package json

    Json API For example:

    Json API For example:

    import play.api.libs.json._
    import play.api.libs.functional.syntax._
    
    case class User(id: Long, name: String, friends: Seq[User] = Seq.empty)
    object User {
    
      // In this format, an undefined friends property is mapped to an empty list
      implicit val format: Format[User] = (
        (__ \ "id").format[Long] and
        (__ \ "name").format[String] and
        (__ \ "friends").lazyFormatNullable(implicitly[Format[Seq[User]]])
          .inmap[Seq[User]](_ getOrElse Seq.empty, Some(_))
      )(User.apply, unlift(User.unapply))
    }
    
    //then in a controller:
    
    object MyController extends Controller {
       def displayUserAsJson(id: String) = Action {
          Ok(Json.toJson(User(id.toLong, "myName")))
       }
       def saveUser(jsonString: String)= Action {
         val user = Json.parse(jsonString).as[User]
         myDataStore.save(user)
         Ok
       }
    }
  • package logback
  • package openid
  • package streams
  • package typedmap
  • package ws

    Provides implicit type classes when you import the package.

  • Codecs
  • Collections
  • Comet
  • EventSource
  • Files
  • JNDI
  • Jsonp
  • package mvc

    Contains the Controller/Action/Result API to handle HTTP requests.

    Contains the Controller/Action/Result API to handle HTTP requests.

    For example, a typical controller:

    class HomeController @Inject() (val controllerComponents: ControllerComponents) extends BaseController {
    
      def index = Action {
        Ok("It works!")
      }
    
    }
    Definition Classes
    api
  • package routing
    Definition Classes
    api
  • package templates
    Definition Classes
    api
  • package test

    Contains test helpers.

    Contains test helpers.

    Definition Classes
    api
p

play.api

libs

package libs

Contains various APIs that are useful while developing web applications.

Source
package.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. libs
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. case class Jsonp(padding: String, json: JsValue) extends Product with Serializable

    JSONP helper.

    JSONP helper.

    Example of use, provided the following route definition:

    GET  /my-service       Application.myService(callback: String)

    The following action definition:

    def myService(callback: String) = Action {
      val json = ...
      Ok(Jsonp(callback, json))
    }

    And the following request:

    GET /my-service?callback=foo

    The response will have content type “application/javascript” and will look like the following:

    foo({...});

    Another example, showing how to serve either JSON or JSONP from the same action, according to the presence of a “callback” parameter in the query string:

    def myService = Action { implicit request =>
      val json = ...
      request.queryString.get("callback").flatMap(_.headOption) match {
        case Some(callback) => Ok(Jsonp(callback, json))
        case None => Ok(json)
      }
    }

Value Members

  1. object Codecs

    Utilities for Codecs operations.

  2. object Collections

    Utilities functions for Collections

  3. object Comet

    Helper function to produce a Comet using Akka Streams.

    Helper function to produce a Comet using Akka Streams.

    Please see https://en.wikipedia.org/wiki/Comet_(programming) for details of Comet.

    Example:

    def streamClock() = Action {
      val df: DateTimeFormatter = DateTimeFormatter.ofPattern("HH mm ss")
      val tickSource = Source.tick(0 millis, 100 millis, "TICK")
      val source = tickSource.map((tick) => df.format(ZonedDateTime.now()))
      Ok.chunked(source via Comet.flow("parent.clockChanged"))
    }
  4. object EventSource

    This class provides an easy way to use Server Sent Events (SSE) as a chunked encoding, using an Akka Source.

    This class provides an easy way to use Server Sent Events (SSE) as a chunked encoding, using an Akka Source.

    Please see the Server-Sent Events specification for details.

    An example of how to display an event stream:

    import java.time.ZonedDateTime
    import java.time.format.DateTimeFormatter
    import javax.inject.Singleton
    import akka.stream.scaladsl.Source
    import play.api.http.ContentTypes
    import play.api.libs.EventSource
    import play.api.mvc._
    
    import scala.concurrent.duration._
    
    def liveClock() = Action {
      val df: DateTimeFormatter = DateTimeFormatter.ofPattern("HH mm ss")
      val tickSource = Source.tick(0 millis, 100 millis, "TICK")
      val source = tickSource.map { (tick) =>
        df.format(ZonedDateTime.now())
      }
      Ok.chunked(source via EventSource.flow).as(ContentTypes.EVENT_STREAM)
    }
  5. object Files

    FileSystem utilities.

  6. object JNDI

    JNDI Helpers.

  7. object Jsonp extends Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped