102

Assuming my web application has full support of PUT and DELETE on the server side, should I make use of them?

Basically my question is how many browsers support this:

<form method="PUT">

or

<form method="DELETE">

Is there any benefits to using these two HTTP Methods other than being REST-compliant? (assuming the replacement for these two methods is the commonly used POST)

Yahel
  • 37,023
  • 22
  • 103
  • 153
Earlz
  • 62,085
  • 98
  • 303
  • 499

5 Answers5

107

Your question involves two closely related but separate standards, HTTP and HTML. The PUT and DELETE methods are part of HTTP. In HTTP they have obvious use in RESTful interfaces, and other services which build on HTTP such as Webdav.

HTML up to version 4 only defines the use of POST and GET for forms. HTML5 at this time appears as though it may support the further methods. [note, support is not included in the current w3 draft]

Any current browser support (I'm not directly aware of any) will be very limited and only really useful as an experiment at the bleeding edge.

leebriggs
  • 3,187
  • 1
  • 20
  • 17
  • 21
    The current HTML5 draft does **not** support `PUT` or `DELETE` in forms. The relevant section is currently in at "last call for comments", so it's _possible_ they'll be implemented but unfortunately it doesn't look like it. I think it was in there at one point and then removed. – Andrew Marshall Mar 02 '11 at 05:45
  • 1
    Regarding browser support, mozilla have this ticket of interest for FF4, which indicates they did support it but have now removed it - https://bugzilla.mozilla.org/show_bug.cgi?id=600813. – leebriggs Mar 02 '11 at 06:29
  • @andrew Indeed, it was part of the draft for several years, but was removed late last year. My intention wasn't to suggest that it will be part of the standard, only that it _may_ be. – leebriggs Mar 02 '11 at 06:35
  • 11
    I'm quite disappointed for the removal of these methods, as they make much sense. Does anyone have a link for the reason behind this decision?. – Tristian Apr 13 '11 at 18:03
  • 5
    @Triztian https://www.w3.org/Bugs/Public/show_bug.cgi?id=10671 and for the full story: http://programmers.stackexchange.com/a/211790/26123 – Paolo Apr 15 '14 at 14:33
32

GET, POST, PUT and DELETE (there are others) are a part of the HTTP standard, but you are limited to GET and POST in HTML forms at this time.

As Andrew mentioned, you can use PUT and DELETE in AJAX requests; however, this only works in some browsers (see http://api.jquery.com/jQuery.ajax/).

BMiner
  • 16,669
  • 12
  • 53
  • 53
21

No, GET & POST are the only valid HTTP method values for the method attribute. See the HTML spec for more information.

I believe you can use them in AJAX requests, though.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
12

As of February 2023, latest HTML specs and drafts still don't have support for methods other than GET and POST by default. If you don't use a method middleware, you are stuck with these two options. (method attribute can also have 'dialog' as a value, but it is irrelevant since it is not directly related to HTTP methods.)

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-method

user3840170
  • 26,597
  • 4
  • 30
  • 62
Gökhan Mete ERTÜRK
  • 3,378
  • 2
  • 19
  • 23
0

It's not really possible to send a DELETE request using <form />, but you can send one to the one API endpoint and redirect the user to another page. This will simulate the desired behaviour. The code with jQuery is provided.

$(".control-action").on("click", () => {
  alert("Click");

  $.ajax({
    // call a DELETE endpoint of API
    url: "/api/items/5",
    method: "DELETE",
    headers: {
      "X-Api-Key": "363463822036d927c733d5607af109e2"
    },
    success : function () {
      // redirect to another page
      // window.location.href = "/items";
    }
  });
});
.link {
  text-decoration: underline;
  cursor: pointer;
  color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

<span class="link control-action">Call action</span>
dragomirik
  • 612
  • 2
  • 6
  • 13