In this section, we'll see how a Play! 2 server is able to render different resources in different ways rather than simply providing HTML pages.
The actions' body in Play! 2 not only have the responsibility of creating resources to be provided to the outside world, but also of declaring how this resource has to be rendered. Fortunately, there are a lot of boilerplates already written for our use in the default actions builder.
The so-called actions builder are the methods we have used almost blindly until now; that is to say, the static methods available in the play.mvc.Results.java
class such as ok
, redirect
, badRequest
, and unauthorized
.
Indeed, these methods have been overloaded several times in order to accept several representations. The following are some examples:
Content
: This takes content that is of the base type of classic string representations such asHtml
,Xml
, andTxt
. This is also the result-type of a rendered template.String
: This will be rendered as is...