don't POST when you should DELETE

2008-10-04 @ 20:46#

one of the big disappointments of how HTTP was implemented from the UA-side (User Agent in this case means common browsers) is that lack of support for PUT and DELETE. this was understandable in the late 1980s and even into the early 1990s. but by now, this has become an embarrassment. it's dead simple to implement PUT and DELETE on servers (ok, you actually need to know what you're doing, but all the plumbing is already there). it's not rocket science for browsers, either. adding method="PUT" or method="DELETE" to an HTML FORM would not take much work. i don't understand why this has not been done.

luckily, there is - today - a simple solution for common browsers. it's the XMLHttpRequest object - Ajax.

it's fairly simple to write a method that will scan the HTML FORM object, collect up all the inputs and commit them to the target URL using a PUT instead of a POST. same for the DELETE cases. a bare-bones sample would look like this:

<form action="/customers/cid-123" method="get" onsubmit="ajax.PutThisResource();return false;">
  <!-- fields and submit button go here -->

<form action="/customers/cid-123/" method="get" onsubmit="ajax.DeleteThisResource();return false;">
  <input type="submit" />

sure, there are a few details; scanning the form, making the Ajax call, handling the return. but that's small stuff. the big point is that using PUT and DELETE are essential to a solid HTTP/REST implementation. and an even bigger point is that there is no excuse for failing to do it.

oh yeah, one more thing. a note to those implementing the 'new wave' of RIA environments (Air, Silverlight, JavaFX) - don't be stupid. support the full range of HTTP methods *now*.