tags:

views:

817

answers:

6

I am not gettng the RESTful thing. Yes, I know how to send a GET request to my app from my browser. It's through URL linking.

<a href="/user/someone">

And can also send POST requests through form method.

<form method="post">

Beside that I know browsers sometimes send HEAD command to figure out page status, but on which the end user has no control.

Then what are those DELETE and PUT commands I am reading of? How do you send, for example a DELETE command from your browser to your RESTful application?

+1  A: 

I've heard that DELETE and PUT is not fully supported in all browsers (I didn't check it). Rails is doing workaround - it is sending POST with a hidden field containing real method. So it really uses only GET and POST and on server it reads this hidden field and reacts on it.

klew
+1  A: 

Flash based applications (or Flex) can work on lower levels, like open sockets. They can also do PUT/DELETE (though Flex in particular is known to have problems with http headers. So I guess I'm saying it depends on your client technology. In particular, you could embed a small flash object that would do the communication for you if your browser doesn't support it (or you don't want to implement cross-browser support).

Assaf Lavie
+5  A: 

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.

Gumbo
See http://stackoverflow.com/questions/165779 for info on browser support.
Chuck
last time I tried http://www.mail-archive.com/[email protected]/msg00336.html there wasn't enough support to build ajax web-dav clients. But I did get the spec changed so agents should support the common safe methods.
Pete Kirkham
+2  A: 

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.

Ron DeVera
+2  A: 

A POST doesn't have to be through a form. The best way to learn about this, and also GET, PUT and DELETE is to use a ReST client to make your HTTP requests and see the responses. I recommend you download the nifty little python client from http://restclient.org/

A browser is (as of now) not your best tool to use while you are acquainting yourself with ReST. A client like the one above will allow you to "see" your HTTP requests and responses.

chefsmart
+3  A: 

@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
Hank Gay