Define a set of extractors allowing to pattern match on the Accept HTTP header of a request
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() => ... }
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 + "]") }
the type of the request body
Provides helpers for creating Action
values.
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.
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.
the type of the request on which this is invoked (input)
the parameter type which blocks executed by this builder take (output)
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.
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.
A request body that adapts automatically according the request Content-Type.
AnyContent - Form url encoded body
AnyContent - Json body
AnyContent - Multipart form data body
AnyContent - Raw body (give access to the raw data as bytes).
AnyContent - Text body
AnyContent - XML body
A body parser parses the HTTP request body content.
A body parser parses the HTTP request body content.
the body content type
Default body parsers.
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.
the request HTTP method
the request URL
A Codec handle the conversion of String to Byte arrays.
A Codec handle the conversion of String to Byte arrays.
The charset to be sent to the client.
The transformation function.
Defines utility methods to generate Action
and Results
types.
Defines utility methods to generate Action
and Results
types.
For example:
object Application extends Controller { def hello(name:String) = Action { request => Ok("Hello " + name) } }
An HTTP cookie.
An HTTP cookie.
the cookie name
the cookie value
the cookie expiration date in seconds, None
for a transient cookie, or a value less than 0 to expire a cookie now
the cookie path, defaulting to the root path /
the cookie domain
whether this cookie is secured, sent only for HTTPS requests
whether this cookie is HTTP only, i.e. not accessible from client-side JavaScipt code
Trait that should be extended by the Cookie helpers.
The HTTP cookies set.
A cookie to be discarded.
A cookie to be discarded. This contains only the data necessary for discarding a cookie.
the name of the cookie to discard
the path of the cookie, defaults to the root path
the cookie domain
whether this cookie is secured
An EssentialAction
underlies every Action
.
An EssentialAction
underlies every Action
. Given a RequestHeader
, an
EssentialAction
consumes the request body (an Array[Byte]
) and returns
a Result
.
An EssentialAction
is a Handler
, which means it is one of the objects
that Play uses to handle requests.
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 } } }
HTTP Flash scope.
HTTP Flash scope.
Flash data are encoded into an HTTP cookie, and can only contain simple String
values.
An Handler handles a request.
An Handler handles a request. Play understands several types of handlers,
for example EssentialAction
s and WebSocket
s.
The Handler
used to handle the request is controlled by GlobalSetting
s's
onRequestReceived
method. The default implementation of
onRequestReceived
delegates to onRouteRequest
which calls the default
Router
.
The HTTP headers set.
Transform a value to a Javascript literal.
Transform a value to a Javascript literal.
Signal a max content size exceeded
Multipart form data body.
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(user.id) } } }
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)
Handle the request body a raw bytes data.
Handle the request body a raw bytes data.
If the content size is bigger than this limit, the content is stored as file.
The complete HTTP request.
The complete HTTP request.
the body content type.
The HTTP request header.
The HTTP request header. Note that it doesn’t contain the request body yet.
A handler that is able to tag requests.
A handler that is able to tag requests. Usually mixed in to other handlers.
A simple HTTP response header, used for standard responses.
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.
the response header, which contains status code and HTTP headers
the response body
the connection semantics to use
Helper utilities to generate results.
HTTP Session.
HTTP Session.
Session data are encoded into an HTTP cookie, and can only contain simple String
values.
A WebSocket handler.
A WebSocket handler.
the type of messages coming in
the type of messages going out
the socket messages generator
Wrap an existing request.
Wrap an existing request. Useful to extend a request.
Helper object to create Action
values.
AnyContent - Empty request body
Helper object to construct BodyParser
values.
Defaults BodyParsers.
Default Codec support.
Helper utilities to encode Cookies.
Helper for creating EssentialAction
s.
Compose the action and the Filters to create a new Action
Compose the action and the Filters to create a new Action
Helper utilities to manage the Flash cookie.
The connection semantics for the result.
Default JavaScript literals converters.
Defines parts handled by Multipart form data.
Default binders for URL path part.
Default binders for Query String
Helper utilities to generate results.
Helpers to create secure actions.
Helper utilities to manage the Session cookie.
Alias types for Sockets
Helper utilities to generate WebSocket results.
Contains the Controller/Action/Result API to handle HTTP requests.
For example, a typical controller: