RESTful web services and HTTP verbs

前端 未结 5 1904
后悔当初
后悔当初 2021-02-19 06:37

What is the minimum set of HTTP verbs that a server should allow for a web service to be classed as RESTful?

What if my hoster doesn\'t permit PUT

相关标签:
5条回答
  • 2021-02-19 07:00

    If you just use GET and POST, it's still RESTful. Your web service may only do things which only required GET or POST, so that's fine.

    0 讨论(0)
  • 2021-02-19 07:00

    REST allows for breaking protocol convention if the implementations of the protocol are broken (so that the only non-standard things you do are to get around the broken parts of the implementation). So it is allowable within REST to use some other method to represent generally unsupported verbs like DELETE or PUT.

    edit: Here is a quote from Fielding, who is the one that created and defined REST:

    A REST API should not contain any changes to the communication protocols aside from filling-out or fixing the details of underspecified bits of standard protocols, such as HTTP’s PATCH method or Link header field. Workarounds for broken implementations (such as those browsers stupid enough to believe that HTML defines HTTP’s method set) should be defined separately, or at least in appendices, with an expectation that the workaround will eventually be obsolete. [Failure here implies that the resource interfaces are object-specific, not generic.]

    0 讨论(0)
  • 2021-02-19 07:19

    You can also use X-Http-Verb-Override:DELETE inst. of HTTP DELETE. This is also usefull for Silverlight clients who cant change the HTTP verbs and only support GET and POST...

    0 讨论(0)
  • 2021-02-19 07:20

    Yes, you can live without PUT and DELETE.

    This article tells you why: http://www.artima.com/lejava/articles/why_put_and_delete.html

    While to true RESTafrians this may be heresy, in the real world you do what you can, with what you have. Be as rational as you can and as consistent with your own convention as you can, but you can definitely build a good RESTful system without P and D.

    rp

    0 讨论(0)
  • 2021-02-19 07:26

    Today's web browsers only handle GETS + POSTS. In Rails, for example, PUTS + DELETES are "faked" through hidden form fields.

    Unless your framework has some workaround to "support" PUTS + DELETES, don't worry about them for now.

    0 讨论(0)
提交回复
热议问题