I just finished building a RESTful API for one of my latest apps. I also built a simple admin interface scaffolding class that will enumerate resources and build simple forms and tables to edit, create, delete etc.
For updating and deleting resources, the class outputs a form with methods of PUT and DELETE, pretty simple:
<form action="/posts/xxxxxxx" method="DELETE">
<input type="submit" value="Delete" />
</form>
and
<form action="/posts/xxxxxxx" method="PUT">
<input type="text" name="username" value="nikcub" />
<input type="text" name="fullname" value="Nik Cubrilovic" />
<input type="text" name="email" value="[email protected]" />
<input type="submit" value="Update" />
</form>
Very simple. If Javascript is detected, then it will intercept the form and use an XMLHTTPRequest to submit back. The Javascript supports the other HTTP methods, but why don't modern browsers support the PUT and DELETE methods? It ends up sending a GET.
I would prefer that when the app gracefully falls back to standard HTML that the same methods are used, instead of having to use hidden fields and the logic for that in the class, or worse, putting the method in the URI and allowing GET to work.
I can't think of any reasons why browsers wouldn't support the other HTTP methods, since developers are just working around it anyway by hacking GET or using POST.
I searched for an answer, and was able to find it specified as part of the XHTML 2.0 spec. There is no mention of it in the HTML5 spec.
Any reason for it not being supported in the 'HTML5 compliant' browsers? Where can I post a request to open this back up and get it implemented in browsers?
Some web frameworks (e.g. Ruby on Rails) get around that by including a hidden _method
parameter in the form with the value of the "actual" method, e.g.:
<form action="/posts/xxxxx" method="POST">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" value="delete">
</form>
The framework then rewrites the request on the server side before processing to use the value of the _method
parameter as the HTTP method.
Don't know if this helps you.