This post from a while back:
RESTful on Play! framework
Illustrated a very elegant approach to designing RESTful Web Services on Play! 1.x with Java.
I am working with Play! v2 and am wondering how easy it is to migrate this approach to the new version. Right off the bat I see that the render method doesn’t exist anymore, so I was wondering if any major architecture changes in the framework prevent this process from being used.
This post:
Play 2.0 RESTful request post-processing
illustrates some of the 2.0 based processing, but it is done in Scala and I am having a devil of a time parsing through it
Whole process in Play 2.0 will be VERY similar the only small differences will be in the syntax, take a look into the documentation .
routesEdit:
Of course you can use
Acceptheader instead offormatparameter, however param is just… easier to set. You can also use ie.user.scala.xmlname for the view, and in the controller render it with:return ok(views.xml.user.render(user).body());I published that sample on the GitHub with some fixes, so you can try it yourself: play-simple-rest
Note that you need to keep
Rest.javacontroller (and its routes) while everything in Application is just for displaying and demonstration (ie making GET/POST/PUT/DELETE calls in controllers).