First we need to make a few adjustments to the code to make the update operation respond to the PUT method and alter the edit form to ensure it is sending in a method of PUT.
|Alter the allowedMethods array to recognize PUT for the update method.|
|Alter the form method to ensure it sends PUT as the method.|
Here we can see that the request was actually done using POST. Internally within the request parameters a PUT method is specified. This is detailed further in the Grails 2.0.0 documentation.
Issuing a request with a method other than GET or POST from a regular browser is not possible without some help from Grails.This doesn't seem to be consistent with the REST architecture or the HTTP v1.1 specification. Grails is also blocking a method of PUT coming from the browser with a 405 - Method Not Allowed response. Requests made with cUrl go through without error.
$ curl --request PUT http://localhost:8080/research-grails-rest/book/update/1 --verboseThe response location, http://localhost:8080/research-grails-rest/book/show/1, indicates the controller received the request correctly and performed the update.
* About to connect() to localhost port 8080 (#0)
* Trying ::1... connected
* Connected to localhost (::1) port 8080 (#0)
> PUT /research-grails-rest/book/update/1 HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: localhost:8080
> Accept: */*
< HTTP/1.1 302 Moved Temporarily
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=F91DEA3433A1F745B249C0F7E3E9988E; Path=/research-grails-rest/; HttpOnly
< Location: http://localhost:8080/research-grails-rest/book/show/1
< Content-Length: 0
< Date: Tue, 24 Jan 2012 10:45:05 GMT
* Connection #0 to host localhost left intact
* Closing connection #0
What am I trying to get at? One concern I have is support by most/all browsers for the HTTP v1.1 specification. Another concern is around the heavy handiness around the method support on Grails part. I concede I am now Grails expert and there may be a very simple solution to this. I haven't found it yet if there is. Furthermore, quick check of delete operation from the browser blocks the DELTE method even after altering the allowedMethods.
So what have we learned? The PUT and DELETE methods have special considerations when involving the Grails built views. It may be worth approaching another framework to interact with the REST services provided. However, the controller has tightly integrated the responses on each call with the next view. I think this is intended due to the nature of Grails application development.