Should I store _method = PUT / DELETE in the message or in the url

I am using ASP.NET MVC to create a RESTful web application, and I plan a tunnel for PUT and DELETE requests through POST, as it seems to be the most pragmatic workaround.

I would like to know if I should tunnel the information at the url:

<form method='post' action='resource?_method=DELETE'> <!-- fields --> </form> 

Or I need to tunnel through the published form data as follows:

 <form method='post' action='resource'> <input type='hidden' name='_method' value='DELETE' /> <!-- fields --> </form> 

And what are the pros and cons of each?

EDIT:. One of the reasons I asked the question is because I read somewhere that placing this kind of information in a URL is a good thing, because mail data is usually lost, but URLs freeze (in log files and etc.) - unfortunately, this makes the URL ugly.

+4
source share
4 answers

This is more of a personal preference. Restful Web Services, OReilly, describes as somewhat interchangeable.

Thus, I prefer the first method for the reasons the programmer intends. In Rest, when I look at the code, I mentally read

VERB http://someuri.com/someresource/id

The verb and the resource are close to each other.

With PUT and DELETE, you should use a workaround similar to the ones you showed. In the first example, the resource and the verb are still close together on the same line.

However, in the second example, the resource is divided into two lines. The verb is included in the same line as the resource identifier, but is located away from the name of the resource. This is very, very insignificant, but for me it makes the second example less readable.

+2
source

Have you seen this question? As I understand it, the x-http-method-override header is the preferred solution to this problem.

+4
source

Not what I have, but should not be used:

 <form method="put" action="resource"> <!-- fields --> </form> 

And / or

 <form method="delete" action="resource"> <!-- fields --> </form> 

...

0
source

They are equivalent.

Although if you click, I would rather send it to the message myself, but it is subjective.

-1
source

All Articles