2012-10-13 18:07:43 +04:00
# Browser enhancements
2012-08-29 23:57:37 +04:00
2012-09-01 23:26:27 +04:00
> "There are two noncontroversial uses for overloaded POST. The first is to *simulate* HTTP's uniform interface for clients like web browsers that don't support PUT or DELETE"
>
> — [RESTful Web Services](1), Leonard Richardson & Sam Ruby.
2012-08-29 23:57:37 +04:00
2012-10-02 18:24:42 +04:00
## Browser based PUT, DELETE, etc...
2012-08-29 23:57:37 +04:00
2012-09-01 23:26:27 +04:00
**TODO: Preamble.** Note that this is the same strategy as is used in [Ruby on Rails ](2 ).
2012-08-29 23:57:37 +04:00
For example, given the following form:
< form action = "/news-items/5" method = "POST" >
< input type = "hidden" name = "_method" value = "DELETE" >
< / form >
`request.method` would return `"DELETE"` .
2012-10-02 18:24:42 +04:00
## Browser based submission of non-form content
2012-08-29 23:57:37 +04:00
Browser-based submission of content types other than form are supported by using form fields named `_content` and `_content_type` :
For example, given the following form:
< form action = "/news-items/5" method = "PUT" >
< input type = "hidden" name = "_content_type" value = "application/json" >
< input name = "_content" value = "{'count': 1}" >
< / form >
2012-10-13 18:07:43 +04:00
`request.content_type` would return `"application/json"` , and `request.stream` would return `"{'count': 1}"`
2012-08-29 23:57:37 +04:00
2012-10-02 18:24:42 +04:00
## URL based accept headers
2012-08-29 23:57:37 +04:00
2012-10-02 18:24:42 +04:00
## URL based format suffixes
2012-08-29 23:57:37 +04:00
2012-09-01 23:26:27 +04:00
## Doesn't HTML5 support PUT and DELETE forms?
2012-08-29 23:57:37 +04:00
2012-10-02 18:24:42 +04:00
Nope. It was at one point intended to support `PUT` and `DELETE` forms, but was later [dropped from the spec ](3 ). There remains [ongoing discussion ](4 ) about adding support for `PUT` and `DELETE` , as well as how to support content types other than form-encoded data.
2012-08-29 23:57:37 +04:00
[1]: http://www.amazon.com/Restful-Web-Services-Leonard-Richardson/dp/0596529260
[2]: http://guides.rubyonrails.org/form_helpers.html#how-do-forms-with-put-or-delete-methods-work
[3]: http://www.w3.org/TR/html5-diff/#changes-2010-06-24
[4]: http://amundsen.com/examples/put-delete-forms/