Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Complete
-
1.2.3.RELEASE
-
None
Description
The JSON controllers generated by Roo violate the specification of the HTTP PUT method defined by W3C (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html)
The URL called for PUT has to be a single resource e.g 'myServer/persons/1' where '1' is the unique identifier of a person resource.
If the resource exists, it gets replaced, else it will be created with the given identifier.
The SpringMVC code generated by Roo maps HTTP PUT requests 'myServer/persons' to the updateFromJson method. The unique identifier is parsed from the body and is not in the url. This is wrong and most RESTful clients will call PUT with the identifier in the URL.
Things are even worse because Roo also creates a showJson method mapped to 'myServer/persons/1' which is NOT limited to a GET request.
This results in getting the showJson method called instead of the updateFromJson method if a proper PUT request with identifier is sent. This makes the use of most of the existing client-side REST frameworks like AngularJS very painful because every controller has to be corrected "by hand".
I attached a Roo script which creates a (wrong) PersonController and I also attached a corrected PersonController that IMHO fits the W3C specification.
BTW: There are other REST dependent issues with like not returning the link of the created resource in createFromJson (HATEOAS) but these will no be part of this issue (Spring Data REST creates quite good REST controllers btw.)