Play 2.0 RESTful request post-processing
- by virtualeyes
In regard to this question I am curious how one can do post-request REST processing a la (crude):
def postProcessor[T](content: T) = {
request match {
case Accepts.Json() => asJson(content)
case Accepts.Xml() => asXml(content)
case _ => content
}
}
overriding onRouteRequest in Global config does not appear to provide access to body of the response, so it would seem that Action composition is the way to go to intercept the response and do post-processing task(s).
Question: is this a good idea, or is it better to do content-type casting directly within a controller (or other class) method where the type to cast is known?
Currently I'm doing this kind of thing everywhere:
toJson( i18n("account not found") )
toJson( Map('orderNum-> orderNum) )
while I'd like the toJson/toXml conversion to happen based on accepts header post-request.