40

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="nikcub@email.com" />
<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?

nikcub
  • 1,414
  • 3
  • 15
  • 16
  • Are you sure about that @JoostBaaij I didn't try it myself but MDN makes no mention of it https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form – George Mauer Oct 22 '13 at 16:00
  • @JoostBaaij Just double checked. Submit this form http://jsbin.com/IWoWiRi/1/ then inspect the request here http://requestb.in/ol62w4ol?inspect in Chrome30, FF24, IE10 `method="PUT"` all shows up as `GET` so I'm sorry but you're wrong. – George Mauer Oct 22 '13 at 16:08
  • If it doesn't, you can still open a telnet connection on port 80 and launch the commands with a client side script. – user2284570 Oct 22 '13 at 20:04
  • @user2284570 what do you mean? The question is about the fact that `
    ` elements don't support `method=PUT` what does telnet have to do with any of that?
    – George Mauer Oct 22 '13 at 20:42
  • Ah, it was only in html elements. Because PUT / DELETE are http commands in the same as GET or POST. – user2284570 Oct 22 '13 at 20:51
  • 3
    Duplicate of http://programmers.stackexchange.com/q/114156/ – BalusC Oct 25 '13 at 17:50
  • Thanks @BalusC it should be noted that this question was asked years earlier – George Mauer Oct 26 '13 at 05:27
  • @GeorgeMauer, user2284570 was just being funny. – Paul Draper Mar 26 '14 at 21:33

3 Answers3

25

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.

Jonathan
  • 7,536
  • 4
  • 30
  • 44
10

Actually i did a very small amount of research & found this answer on other Stackexchange forum.

I know it's not a good answer to post a link but i don't know the exact answer. So, it's the only way you can solve your doubt.

https://softwareengineering.stackexchange.com/questions/114156/why-there-are-no-put-and-delete-methods-in-html-forms

Community
  • 1
  • 1
Akshit Zaveri
  • 4,166
  • 6
  • 30
  • 59
8

HTML 4.01 supports only post and get, see http://www.w3.org/TR/html4/interact/forms.html#h-17.3 Not sure about other HTML specs.

Harri
  • 2,692
  • 2
  • 21
  • 25
  • 1
    ye I know that, I am wondering why, with the popularity of REST today, it is not being implemented in "HTML5 browsers" – nikcub Mar 04 '11 at 06:33
  • XHTML 2 (XForms 1.1 to be more precise) spec includes PUT and DELETE methods. See http://www.w3.org/TR/xforms11/#submit-put – Harri Mar 04 '11 at 07:28
  • HTML5 in its current state does not include those methods, http://dev.w3.org/html5/spec/Overview.html#attr-fs-method – Harri Mar 04 '11 at 07:29