How do you send anything beside GET and POST from browser to your RESTful app?

The HTML 4.01 specification describes only GET and POST as valid values for the method attribute. So in HTML there is no way of describing other methods than this by now.

But the HTML 5 specification (currently just a working draft) does name PUT and DELETE as valid values.

Taking a look into the XMLHttpRequest object specification (currently just a working draft too) used for asynchronous requests in JavaScript (AJAX), it supports the PUT and DELETE methods too, but doesn’t say anything about the actual support by current browsers.


To simulate PUT and DELETE, frameworks like Rails instead build forms like this:

<form action="/users/1/delete" method="post">
    <input type="hidden" name="_method" value="delete" />
    <input type="submit" value="Delete user 1" />
</form>

This is actually a POST form, but using the hidden _method input to tell the server which method was really intended. You could implement this support on any other web framework as well.


@C Moran is right: if you want to be truly RESTful, a browser isn't an ideal client, due in part to the lack HTTP methods beyond GET and POST. However, if you really want to do it from a browser, you can use AJAX to send PUTs and DELETEs, e.g. YUI's Connection Manager allows you specify any of the following HTTP methods:

  • GET
  • POST
  • HEAD
  • PUT
  • DELETE

Tags:

Http

Rest