O'Reilly logo

Play Framework Essentials by Julien Richard-Foy

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

Handling content negotiation

The same HTTP POST endpoints can process the JSON content as well as the URL-encoded content; however, GET endpoints, which previously returned JSON content, now only return HTML content. Is it possible to return both the JSON and HTML content from the same GET endpoints (similarly to what has been done for POST endpoints)?

The answer is yes, and this HTTP feature is named content negotiation. The word negotiation comes from the fact that HTTP clients inform servers of which versions of a resource they would rather get (according to their capabilities). They do this by specifying HTTP request headers starting with Accept. For instance, your web browser usually sends, along with each request, an Accept-Language header ...

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