Is there any reason not to use HTTP PUT and DELETE in a web application?

后端 未结 7 776
深忆病人
深忆病人 2021-01-31 03:04

Looking around, I can\'t name a single web application (not web service) that uses anything besides GET and POST requests. Is there a specific reason for this? Do some browsers

7条回答
  •  -上瘾入骨i
    2021-01-31 03:36

    Actually a fair amount of people use PUT and DELETE, mostly for non-browser APIs. Some examples are the Atom Publishing Protocol and the Google Data APIs:

    • http://www.ietf.org/rfc/rfc5023.txt
    • http://code.google.com/apis/gdata/docs/2.0/basics.html

    Beyond that, you don't see PUT/DELETE in common usage because most browsers don't support PUT and DELETE through Forms. HTML5 seems to be fixing this:

    • http://www.w3.org/TR/html5/forms.html#form-submission-0

    The way it works for browser applications is: people design RESTful applications with PUT and DELETE in mind, then "tunnel" those requests through POSTs from the browser. For example, see this SO question on how Ruby on Rails accomplishes this using hidden fields:

    • How can I emulate PUT/DELETE for Rails and GWT?

    So, you wouldn't be on your own designing your application with the larger set of HTTP verbs in mind.

    EDIT: By the way, if you're curious about why PUT/DELETE are missing from browser based form posts, it turns out there's no real good technical reason. Reading around this thread on the rest-discuss mailing list, especially Roy Fielding's comments, is interesting for some context:

    • http://tech.groups.yahoo.com/group/rest-discuss/message/9620?threaded=1&var=1&l=1&p=13

    EDIT: There are some comments on whether AJAX libraries support all the methods. It does come down to the actual browser implementation of XMLHttpRequest. I thought someone might find this link handy, which tests your browser to see how compliant the HttpRequest object is with various HTTP options.

    • http://www.mnot.net/javascript/xmlhttprequest/

    Unfortunately, I don't know of a reference which collects these results.

提交回复
热议问题