How to perform "less popular" HTTP actions in a RESTful web application?

I am developing a Python web application as a training exercise, and I am looking for my RESTful application.

To this end, I want to be able to handle various types of HTTP actions / verbs, where applicable. For example, if the widget with id 12 is represented by the URI http: // domain / widget / 12 , and I want to give the end user the ability to remove this widget, they should be able to make an HTTP DELETE request against / widget / 12.

However, HTML forms only support GET and POST, as far as I know, so how can I make an HTTP request with "less popular" HTTP actions like DELETE?

Let's say that on the widget 12 view page (returned by the HTTP GET), I want to enable the form with only one submit button to remove this widget. For instance:

<form action="/widget/12" method="DELETE"> <input type="submit" value="Delete Me!" /> </form> 

However, he has already established that HTML forms do not support DELETE for a method attribute. So, what is the RESTful way to execute a DELETE request from the client in this situation?

+4
source share
3 answers

In the browser, you will need to use XmlHttpRequest (Ajax) for the described scenario. If your client or server does not support additional methods, it is customary to use your own X-HTTP-Method-Override header to indicate the action.

+7
source

You either tunnel commands through POST, or use Ajax, or both - (post-tunneling acts like a rollback when javascript support is not found)

+1
source

Stephen Walter had a wonderful blog post today.

http://stephenwalther.com/blog/archive/2009/01/21/asp.net-mvc-tip-46-ndash-donrsquot-use-delete-links-because.aspx

Depending on how strictly you want to adhere to the concept of "RESTful", using POST to perform the removal will not appeal to you.

+1
source

All Articles