play.api

package play.api

Contains the public API for Scala developers.

==== 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)

Attributes

Members list

Packages

package play.api.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
 )
)

Attributes

package play.api.http

Contains standard HTTP constants. For example:

Contains standard HTTP constants. For example:

val text = ContentTypes.TEXT
val ok = Status.OK
val accept = HeaderNames.ACCEPT

Attributes

package play.api.i18n

Contains the internationalisation API.

Contains the internationalisation API.

For example, translating a message:

val msgString = Messages("items.found", items.size)

Attributes

package play.api.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.

Attributes

See also

The Module class for information on how to provide bindings.

package play.api.libs

Contains various APIs that are useful while developing web applications.

Contains various APIs that are useful while developing web applications.

Attributes

package play.api.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!")
 }

}

Attributes

Type members

Classlikes

trait Application

A Play application.

A Play application.

Application creation is handled by the framework engine.

If you need to create an ad-hoc application, for example in case of unit testing, you can easily achieve this using:

val application = new DefaultApplication(new File("."), this.getClass.getClassloader, None, Play.Mode.Dev)

This will create an application using the current classloader.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Application

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

Loads an application. This is responsible for instantiating an application given a context.

Loads an application. This is responsible for instantiating an application given a context.

Application loaders are expected to instantiate all parts of an application, wiring everything together. They may be manually implemented, if compile time wiring is preferred, or core/third party implementations may be used, for example that provide a runtime dependency injection framework.

During dev mode, an ApplicationLoader will be instantiated once, and called once, each time the application is reloaded. In prod mode, the ApplicationLoader will be instantiated and called once when the application is started.

Out of the box Play provides a Guice module that defines a Java and Scala default implementation based on Guice, as well as various helpers like GuiceApplicationBuilder. This can be used simply by adding the "PlayImport.guice" dependency in build.sbt.

A custom application loader can be configured using the play.application.loader configuration property. Implementations must define a no-arg constructor.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

Helper to provide the Play built in components.

Helper to provide the Play built in components.

Attributes

Supertypes
class Object
trait Matchable
class Any
Show all
Known subtypes

This helper class provides all the built-in component dependencies by trading them for a single dependency

This helper class provides all the built-in component dependencies by trading them for a single dependency

  • the application loader context.

Attributes

Supertypes
class Object
trait Matchable
class Any
Show all

This helper trait provides all the built-in component dependencies by trading them for a single dependency

This helper trait provides all the built-in component dependencies by trading them for a single dependency

  • the application loader context.

Attributes

Supertypes
class Object
trait Matchable
class Any
Show all
Known subtypes
@Singleton
class DefaultApplication(val environment: Environment, applicationLifecycle: ApplicationLifecycle, val injector: Injector, val configuration: Configuration, val requestFactory: RequestFactory, val requestHandler: HttpRequestHandler, val errorHandler: HttpErrorHandler, val actorSystem: ActorSystem, val materializer: Materializer, val coordinatedShutdown: CoordinatedShutdown) extends Application

Attributes

Supertypes
trait Application
class Object
trait Matchable
class Any
class DefaultMarkerContext(someMarker: Marker) extends MarkerContext

A default marker context. This is used by MarkerContext.apply, but can also be used to provide explicit typing for markers. For example, to define a SecurityContext marker, you can define a case object extending DefaultMarkerContext:

A default marker context. This is used by MarkerContext.apply, but can also be used to provide explicit typing for markers. For example, to define a SecurityContext marker, you can define a case object extending DefaultMarkerContext:

case object SecurityMarkerContext extends DefaultMarkerContext(MarkerFactory.getMarker("SECURITY"))

Value parameters

someMarker

a marker used in the marker method.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Logger extends LoggerLike

A Play logger.

A Play logger.

Value parameters

logger

the underlying SL4FJ logger

Attributes

Companion
object
Supertypes
trait LoggerLike
class Object
trait Matchable
class Any
object Logger

High-level API for logging operations.

High-level API for logging operations.

For example, logging with the default application logger:

Logger.info("Hello!")

Logging with a custom logger:

Logger("my.logger").info("Hello!")

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Logger.type

Runs through underlying logger configuration.

Runs through underlying logger configuration.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
trait LoggerLike

Typical logger interface.

Typical logger interface.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Logger
trait Logging

A trait that can mixed into a class or trait to add a logger named based on the class name.

A trait that can mixed into a class or trait to add a logger named based on the class name.

Attributes

Supertypes
class Object
trait Matchable
class Any

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object MarkerContext

A MarkerContext trait, to provide easy access to org.slf4j.Marker in Logger API. This is usually accessed with a marker through an implicit conversion from a Marker.

A MarkerContext trait, to provide easy access to org.slf4j.Marker in Logger API. This is usually accessed with a marker through an implicit conversion from a Marker.

 implicit val markerContext: MarkerContext = org.slf4j.MarkerFactory.getMarker("EXAMPLEMARKER")
 log.error("This message will be logged with the EXAMPLEMARKER marker")

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

A component to mix in when no default filters should be mixed in to BuiltInComponents.

A component to mix in when no default filters should be mixed in to BuiltInComponents.

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
final class OptionalDevContext(val devContext: Option[DevContext])

Represents an Option[DevContext] so that it can be used for dependency injection. We can't easily use a plain Option[DevContext] since Java erases the type parameter of that type.

Represents an Option[DevContext] so that it can be used for dependency injection. We can't easily use a plain Option[DevContext] since Java erases the type parameter of that type.

Attributes

Supertypes
class Object
trait Matchable
class Any
final class OptionalSourceMapper(val sourceMapper: Option[SourceMapper])

Represents an Option[SourceMapper] so that it can be used for dependency injection. We can't easily use a plain Option[SourceMapper] since Java erases the type parameter of that type.

Represents an Option[SourceMapper] so that it can be used for dependency injection. We can't easily use a plain Option[SourceMapper] since Java erases the type parameter of that type.

Attributes

Supertypes
class Object
trait Matchable
class Any
@Singleton
final class OptionalSourceMapperProvider(optDevContext: OptionalDevContext) extends Provider[OptionalSourceMapper]

Attributes

Supertypes
trait Provider[OptionalSourceMapper]
class Object
trait Matchable
class Any
object Play

High-level API to access Play global features.

High-level API to access Play global features.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Play.type
case class UnexpectedException(message: Option[String], unexpected: Option[Throwable]) extends PlayException

Generic exception for unexpected error cases.

Generic exception for unexpected error cases.

Attributes

Supertypes
trait Product
trait Equals
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all