Package

play.api

mvc

Permalink

package mvc

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

For example, a typical controller:

object Application extends Controller {

  def index = Action {
    Ok("It works!")
  }

}
Source
package.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. mvc
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. trait AcceptExtractors extends AnyRef

    Permalink

    Define a set of extractors allowing to pattern match on the Accept HTTP header of a request

  2. case class Accepting(mimeType: String) extends Product with Serializable

    Permalink

    Convenient class to generate extractors checking if a given mime type matches the Accept header of a request.

    Convenient class to generate extractors checking if a given mime type matches the Accept header of a request. Example of use:

    val AcceptsMp3 = Accepting("audio/mp3")

    Then:

    request match {
      case AcceptsMp3() => ...
    }
  3. trait Action[A] extends EssentialAction

    Permalink

    An action is essentially a (Request[A] => Result) function that handles a request and generates a result to be sent to the client.

    An action is essentially a (Request[A] => Result) function that handles a request and generates a result to be sent to the client.

    For example,

    val echo = Action { request =>
      Ok("Got request [" + request + "]")
    }
    A

    the type of the request body

  4. trait ActionBuilder[+R[_]] extends ActionFunction[Request, R]

    Permalink

    Provides helpers for creating Action values.

  5. trait ActionFilter[R[_]] extends ActionRefiner[R, R]

    Permalink

    A simple kind of ActionRefiner which, given a request (of type R), may either immediately produce a Result (for example, an error), or continue its Action block with the same request.

    A simple kind of ActionRefiner which, given a request (of type R), may either immediately produce a Result (for example, an error), or continue its Action block with the same request. The critical (abstract) function is filter.

  6. trait ActionFunction[-R[_], +P[_]] extends AnyRef

    Permalink

    A builder for generic Actions that generalizes over the type of requests.

    A builder for generic Actions that generalizes over the type of requests. An ActionFunction[R,P] may be chained onto an existing ActionBuilder[R] to produce a new ActionBuilder[P] using andThen. The critical (abstract) function is invokeBlock. Most users will want to use ActionBuilder instead.

    R

    the type of the request on which this is invoked (input)

    P

    the parameter type which blocks executed by this builder take (output)

  7. trait ActionRefiner[-R[_], +P[_]] extends ActionFunction[R, P]

    Permalink

    A simple kind of ActionFunction which, given a request (of type R), may either immediately produce a Result (for example, an error), or call its Action block with a parameter (of type P).

    A simple kind of ActionFunction which, given a request (of type R), may either immediately produce a Result (for example, an error), or call its Action block with a parameter (of type P). The critical (abstract) function is refine.

  8. trait ActionTransformer[-R[_], +P[_]] extends ActionRefiner[R, P]

    Permalink

    A simple kind of ActionRefiner which, given a request (of type R), unconditionally transforms it to a new parameter type (P) to be passed to its Action block.

    A simple kind of ActionRefiner which, given a request (of type R), unconditionally transforms it to a new parameter type (P) to be passed to its Action block. The critical (abstract) function is transform.

  9. sealed trait AnyContent extends AnyRef

    Permalink

    A request body that adapts automatically according the request Content-Type.

  10. case class AnyContentAsFormUrlEncoded(data: Map[String, Seq[String]]) extends AnyContent with Product with Serializable

    Permalink

    AnyContent - Form url encoded body

  11. case class AnyContentAsJson(json: JsValue) extends AnyContent with Product with Serializable

    Permalink

    AnyContent - Json body

  12. case class AnyContentAsMultipartFormData(mdf: MultipartFormData[TemporaryFile]) extends AnyContent with Product with Serializable

    Permalink

    AnyContent - Multipart form data body

  13. case class AnyContentAsRaw(raw: RawBuffer) extends AnyContent with Product with Serializable

    Permalink

    AnyContent - Raw body (give access to the raw data as bytes).

  14. case class AnyContentAsText(txt: String) extends AnyContent with Product with Serializable

    Permalink

    AnyContent - Text body

  15. case class AnyContentAsXml(xml: NodeSeq) extends AnyContent with Product with Serializable

    Permalink

    AnyContent - XML body

  16. trait BodyParser[+A] extends (RequestHeader) ⇒ Accumulator[ByteString, Either[Result, A]]

    Permalink

    A body parser parses the HTTP request body content.

    A body parser parses the HTTP request body content.

    A

    the body content type

  17. trait BodyParsers extends AnyRef

    Permalink

    Default body parsers.

  18. case class Call(method: String, url: String, fragment: String = null) extends mvc.Call with Product with Serializable

    Permalink

    Defines a Call, which describes an HTTP request and can be used to create links or fill redirect data.

    Defines a Call, which describes an HTTP request and can be used to create links or fill redirect data.

    These values are usually generated by the reverse router.

    method

    the request HTTP method

    url

    the request URL

  19. case class Codec(charset: String)(encode: (String) ⇒ ByteString, decode: (ByteString) ⇒ String) extends Product with Serializable

    Permalink

    A Codec handle the conversion of String to Byte arrays.

    A Codec handle the conversion of String to Byte arrays.

    charset

    The charset to be sent to the client.

    encode

    The transformation function.

  20. trait Controller extends Results with BodyParsers with HttpProtocol with Status with HeaderNames with ContentTypes with RequestExtractors with Rendering

    Permalink

    Defines utility methods to generate Action and Results types.

    Defines utility methods to generate Action and Results types.

    For example:

    class HomeController @Inject()() extends Controller {
    
      def hello(name:String) = Action { request =>
        Ok("Hello " + name)
      }
    
    }
  21. case class Cookie(name: String, value: String, maxAge: Option[Int] = None, path: String = "/", domain: Option[String] = None, secure: Boolean = false, httpOnly: Boolean = true) extends Product with Serializable

    Permalink

    An HTTP cookie.

    An HTTP cookie.

    name

    the cookie name

    value

    the cookie value

    maxAge

    the cookie expiration date in seconds, None for a transient cookie, or a value less than 0 to expire a cookie now

    path

    the cookie path, defaulting to the root path /

    domain

    the cookie domain

    secure

    whether this cookie is secured, sent only for HTTPS requests

    httpOnly

    whether this cookie is HTTP only, i.e. not accessible from client-side JavaScipt code

  22. trait CookieBaker[T <: AnyRef] extends AnyRef

    Permalink

    Trait that should be extended by the Cookie helpers.

  23. trait Cookies extends Traversable[Cookie]

    Permalink

    The HTTP cookies set.

  24. case class DiscardingCookie(name: String, path: String = "/", domain: Option[String] = None, secure: Boolean = false) extends Product with Serializable

    Permalink

    A cookie to be discarded.

    A cookie to be discarded. This contains only the data necessary for discarding a cookie.

    name

    the name of the cookie to discard

    path

    the path of the cookie, defaults to the root path

    domain

    the cookie domain

    secure

    whether this cookie is secured

  25. trait EssentialAction extends (RequestHeader) ⇒ Accumulator[ByteString, Result] with Handler

    Permalink

    An EssentialAction underlies every Action.

    An EssentialAction underlies every Action. Given a RequestHeader, an EssentialAction consumes the request body (an ByteString) and returns a Result.

    An EssentialAction is a Handler, which means it is one of the objects that Play uses to handle requests.

  26. trait EssentialFilter extends AnyRef

    Permalink
  27. trait Filter extends EssentialFilter

    Permalink

    Implement this interface if you want to add a Filter to your application

    Implement this interface if you want to add a Filter to your application

    object AccessLog extends Filter {
      override def apply(next: RequestHeader => Future[Result])(request: RequestHeader): Future[Result] = {
    		 val result = next(request)
    		 result.map { r => play.Logger.info(request + "\n\t => " + r; r }
    	 }
    }
  28. case class Flash(data: Map[String, String] = Map.empty[String, String]) extends Product with Serializable

    Permalink

    HTTP Flash scope.

    HTTP Flash scope.

    Flash data are encoded into an HTTP cookie, and can only contain simple String values.

  29. trait Handler extends AnyRef

    Permalink

    An Handler handles a request.

    An Handler handles a request. Play understands several types of handlers, for example EssentialActions and WebSockets.

    The Handler used to handle the request is controlled by GlobalSettings's onRequestReceived method. The default implementation of onRequestReceived delegates to onRouteRequest which calls the default Router.

  30. class Headers extends AnyRef

    Permalink

    The HTTP headers set.

  31. trait JavascriptLiteral[A] extends AnyRef

    Permalink

    Transform a value to a Javascript literal.

    Transform a value to a Javascript literal.

    Annotations
    @implicitNotFound( ... )
  32. trait LegacyI18nSupport extends AnyRef

    Permalink
  33. case class MaxSizeExceeded(length: Long) extends MaxSizeStatus with Product with Serializable

    Permalink

    Signal a max content size exceeded.

  34. sealed trait MaxSizeStatus extends AnyRef

    Permalink

    The status of a max size flow.

  35. case class MultipartFormData[A](dataParts: Map[String, Seq[String]], files: Seq[FilePart[A]], badParts: Seq[BadPart]) extends Product with Serializable

    Permalink

    Multipart form data body.

  36. trait PathBindable[A] extends AnyRef

    Permalink

    Binder for URL path parameters.

    Binder for URL path parameters.

    You can provide an implementation of PathBindable[A] for any type A you want to be able to bind directly from the request path.

    For example, given this class definition:

    case class User(id: Int, name: String, age: Int)

    You can define a binder retrieving a User instance from its id, useable like the following:

    // In your routes:
    // GET  /show/:user      controllers.Application.show(user)
    // For example: /show/42
    
    object Application extends Controller {
      def show(user: User) = Action {
        ...
      }
    }

    The definition of binder can look like the following:

    object User {
      implicit def pathBinder(implicit intBinder: PathBindable[Int]) = new PathBindable[User] {
        override def bind(key: String, value: String): Either[String, User] = {
          for {
            id <- intBinder.bind(key, value).right
            user <- User.findById(id).toRight("User not found").right
          } yield user
        }
        override def unbind(key: String, user: User): String = {
          intBinder.unbind(key, user.id)
        }
      }
    }
    Annotations
    @implicitNotFound( ... )
  37. trait QueryStringBindable[A] extends AnyRef

    Permalink

    Binder for query string parameters.

    Binder for query string parameters.

    You can provide an implementation of QueryStringBindable[A] for any type A you want to be able to bind directly from the request query string.

    For example, if you have the following type to encode pagination:

    /**
     * @param index Current page index
     * @param size Number of items in a page
     */
    case class Pager(index: Int, size: Int)

    Play will create a Pager(5, 42) value from a query string looking like /foo?p.index=5&p.size=42 if you define an instance of QueryStringBindable[Pager] available in the implicit scope.

    For example:

    object Pager {
      implicit def queryStringBinder(implicit intBinder: QueryStringBindable[Int]) = new QueryStringBindable[Pager] {
        override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, Pager]] = {
          for {
            index <- intBinder.bind(key + ".index", params)
            size <- intBinder.bind(key + ".size", params)
          } yield {
            (index, size) match {
              case (Right(index), Right(size)) => Right(Pager(index, size))
              case _ => Left("Unable to bind a Pager")
            }
          }
        }
        override def unbind(key: String, pager: Pager): String = {
          intBinder.unbind(key + ".index", pager.index) + "&" + intBinder.unbind(key + ".size", pager.size)
        }
      }
    }

    To use it in a route, just write a type annotation aside the parameter you want to bind:

    GET  /foo        controllers.foo(p: Pager)
    Annotations
    @implicitNotFound( ... )
  38. case class RawBuffer(memoryThreshold: Int, initialData: ByteString = ByteString.empty) extends Product with Serializable

    Permalink

    Handle the request body a raw bytes data.

    Handle the request body a raw bytes data.

    memoryThreshold

    If the content size is bigger than this limit, the content is stored as file.

  39. trait Rendering extends AnyRef

    Permalink
  40. trait Request[+A] extends RequestHeader

    Permalink

    The complete HTTP request.

    The complete HTTP request.

    A

    the body content type.

    Annotations
    @implicitNotFound( "Cannot find any HTTP Request here" )
  41. trait RequestExtractors extends AcceptExtractors

    Permalink
  42. trait RequestHeader extends AnyRef

    Permalink

    The HTTP request header.

    The HTTP request header. Note that it doesn’t contain the request body yet.

    Annotations
    @implicitNotFound( ... )
  43. trait RequestTaggingHandler extends Handler

    Permalink

    A handler that is able to tag requests.

    A handler that is able to tag requests. Usually mixed in to other handlers.

  44. final class ResponseHeader extends AnyRef

    Permalink

    A simple HTTP response header, used for standard responses.

  45. case class Result(header: ResponseHeader, body: HttpEntity) extends Product with Serializable

    Permalink

    A simple result, which defines the response header and a body ready to send to the client.

    A simple result, which defines the response header and a body ready to send to the client.

    header

    the response header, which contains status code and HTTP headers

    body

    the response body

  46. trait Results extends AnyRef

    Permalink

    Helper utilities to generate results.

  47. case class Session(data: Map[String, String] = Map.empty[String, String]) extends Product with Serializable

    Permalink

    HTTP Session.

    HTTP Session.

    Session data are encoded into an HTTP cookie, and can only contain simple String values.

  48. trait WebSocket extends Handler

    Permalink

    A WebSocket handler.

  49. class WrappedRequest[+A] extends Request[A]

    Permalink

    Wrap an existing request.

    Wrap an existing request. Useful to extend a request.

  50. class WithFilters extends GlobalSettings

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 2.5.0) Use dependency injection

Value Members

  1. object Action extends ActionBuilder[Request]

    Permalink

    Helper object to create Action values.

  2. object AnyContentAsEmpty extends AnyContent with Product with Serializable

    Permalink

    AnyContent - Empty request body

  3. object BodyParser

    Permalink

    Helper object to construct BodyParser values.

  4. object BodyParsers extends BodyParsers

    Permalink

    Defaults BodyParsers.

  5. object Codec extends Serializable

    Permalink

    Default Codec support.

  6. object Cookies

    Permalink

    Helper utilities to encode Cookies.

  7. object EssentialAction

    Permalink

    Helper for creating EssentialActions.

  8. object Filter

    Permalink
  9. object FilterChain

    Permalink

    Compose the action and the Filters to create a new Action

  10. object Filters

    Permalink

    Compose the action and the Filters to create a new Action

  11. object Flash extends CookieBaker[Flash] with Serializable

    Permalink

    Helper utilities to manage the Flash cookie.

  12. object Headers

    Permalink
  13. object JavascriptLiteral

    Permalink

    Default JavaScript literals converters.

  14. object MaxSizeNotExceeded extends MaxSizeStatus with Product with Serializable

    Permalink

    Signal max size is not exceeded.

  15. object MultipartFormData extends Serializable

    Permalink

    Defines parts handled by Multipart form data.

  16. object PathBindable

    Permalink

    Default binders for URL path part.

  17. object QueryStringBindable

    Permalink

    Default binders for Query String

  18. object RangeResult

    Permalink
  19. object Request

    Permalink
  20. object RequestHeader

    Permalink
  21. object ResponseHeader

    Permalink
  22. object Results extends Results with LegacyI18nSupport

    Permalink

    Helper utilities to generate results.

  23. object Security

    Permalink

    Helpers to create secure actions.

  24. object Session extends CookieBaker[Session] with Serializable

    Permalink

    Helper utilities to manage the Session cookie.

  25. object Socket

    Permalink

    Alias types for Sockets

  26. object WebSocket

    Permalink

    Helper utilities to generate WebSocket results.

Inherited from AnyRef

Inherited from Any

Ungrouped