Wednesday, January 25, 2012

REST - Taking a Closer Look (Part 6)

In my last post, I talked a bit more about the PUT and DELETE methods of a request.  I raised a concern regarding the Grails and it's support for PUT and DELETE due to my inabilities to make a PUT request from a form.  After further investigation, I found a reference in the HTML5 changelogs posted on June 24, 2010 indicating that PUT and DELETE methods were removed from the specification.

As expected, the following code works without any issues.

jQuery.ajax({ url: "http://localhost:8080/research-grails-rest/book/delete/2", type: "DELETE" });

This further proves the point that only the form submission using these methods are affected.  This restriction may not be an issue for applications that are primarily Ajax driven.  However, I have read in several API docs now something similar to this from the jQuery Ajax documentation.
"The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers."
The trend in several stackoverflow articles is a POST tunneling concept.  Essentially, instead of using the PUT or DELETE methods, send everything over POST.  Then specify through a hidden form input or HTTP header the correct method.  This resolves the problem for form submissions and lack of browser support.

With that resolved, it is time to look closer at more complex structures.  My next post will be centered around understanding how the state of a collection of books is transferred.  After that investigating how to perform operations against that collection.

Citations from stackoverflow.com regarding POST tunneling:

No comments:

Post a Comment