Play 2.0 RESTful request post-processing
Posted
by
virtualeyes
on Stack Overflow
See other posts from Stack Overflow
or by virtualeyes
Published on 2012-06-16T17:13:37Z
Indexed on
2012/06/16
21:16 UTC
Read the original article
Hit count: 271
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.
© Stack Overflow or respective owner