O'Reilly logo

Mastering Play Framework for Scala by Shiti Saxena

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Content negotiation

According to HTTP:

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): ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required