Content negotiation is the process of selecting the best representation for a given response when there are multiple representations available.
It can either be server-driven or agent-driven or a combination of both, which is called transparent negotiation. Play provides support for server-driven negotiations. This is handled by the rendering trait and is extended by the controller trait. The controller trait is the one where the controller objects in a Play app extend.
Let's look at the Rendering
trait:
trait Rendering { object render { //Tries to render the most acceptable result according to the request's Accept header value. def apply(f: PartialFunction[MediaRange, Result])(implicit request: RequestHeader): Result = { def _render(ms: Seq[MediaRange]): Result = ms match { case Nil => NotAcceptable case Seq(m, ms @ _*) => f.applyOrElse(m, (m: MediaRange) => _render(ms)) } // "If...