vicaba
vicaba

Reputation: 2876

Play Framework 2, why Actions and Requests take a type parameter?

Why Actions and Requests in Play Framework take a type parameter like in this code below?

import play.api.mvc._

case class Logging[A](action: Action[A]) extends Action[A] {

  def apply(request: Request[A]): Future[SimpleResult] = {
    Logger.info("Calling action")
    action(request)
  }

  lazy val parser = action.parser
}

Upvotes: 0

Views: 629

Answers (1)

anquegi
anquegi

Reputation: 11522

If you look at the action documentation here

this type is

type BODY_CONTENT = A

Type of the request body.

if you Know that, you can apply that

text/plain: String
application/json: JsValue
text/xml: NodeSeq
application/form-url-encoded: Map[String, Seq[String]]
multipart/form-data: MultipartFormData[TemporaryFile]
any other content type: RawBuffer

Take also a look here: on body parsers

https://www.playframework.com/documentation/2.0/ScalaBodyParsers

Upvotes: 1

Related Questions