May 2015
Intermediate to advanced
274 pages
5h 11m
English
In Play, the response to a request is a result. A result has two components: the response header and the response body. Let's look at a simple example of this:
def plainResult = Action {
Result(
header = ResponseHeader(200, Map(CONTENT_TYPE -> "text/plain")),
body = Enumerator("This is the response from plainResult method".getBytes())
)
}Notice that we used an enumerator for the response body. An enumerator is a means to provide data to an iteratee. We will discuss these in detail in Chapter 6, Reactive Data Streams.
Apart from this, a result has additional functions that equips us with better means to handle response headers, sessions, cookies, and so on.
A result can send JSON, XML, and images as a response, apart from a String ...
Read now
Unlock full access