How do you send something next to GET and POST from a browser to your RESTful app?

I do not get RESTful thing. Yes, I know how to send a GET request to my application from my browser. This is through the URL link.

<a href="/user/someone"> 

And it can also send POST requests via the form method.

 <form method="post"> 

In addition, I know that browsers sometimes send a HEAD command to determine the state of a page, but on which the end user has no control.

Then which DELETE and PUT commands do I read? How do you send, for example, a DELETE command from your browser to your RESTful application?

+6
rest
source share
6 answers

The HTML 4.01 specification describes only GET and POST as valid values ​​for the method attribute . Thus, in HTML there is no way to describe other methods than it is now.

But the HTML 5 specification (currently only a working draft) calls PUT and DELETE as valid values .

A look at the XMLHttpRequest object specification (currently only a working draft) used for asynchronous requests in JavaScript ( AJAX ), it supports the PUT and DELETE methods , but says nothing about the actual support of current browsers.

+5
source share

To mimic PUT and DELETE, frameworks such as Rails instead create 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 form of POST, but using the _method hidden input to tell the server which method was actually intended. You can also implement this support on any other web platform.

+3
source share

@C Moran is right: if you want to be truly RESTful, the browser is not an ideal client, partly due to the lack of HTTP methods outside of GET and POST . However, if you really want to do this from a browser, you can use AJAX to send PUT and DELETE s, for example. YUI Connection Manager allows you to specify any of the following HTTP methods:

  • GET
  • POST
  • HEAD
  • PUT
  • DELETE
+3
source share

I heard that DELETE and PUT are not fully supported in all browsers (I have not tested this). Rails makes a workaround - it sends a POST with a hidden field containing the actual method. Therefore, he really uses only GET and POST, and on the server he reads this hidden field and reacts to it.

+2
source share

POST must not go through the form. The best way to find out about this, as well as GET, PUT, and DELETE, is to use the ReST client to create your HTTP requests and view the responses. I recommend you download the great python client from http://restclient.org/

The browser (at the moment) is not the best tool to use when you are familiar with the registry. A client like the one above will allow you to "see" your HTTP requests and responses.

+2
source share

Flash (or Flex) -based applications can run at lower levels, such as open sockets. They can also perform PUT / DELETE (although Flex, in particular, has problems with http headers. Therefore, I think I say it depends on your client technology. In particular, you can insert a small flash object that will communicate for you if your browser does not support it (or you do not want to use cross-browser support).

+1
source share

All Articles