Rails Put vs Post

后端 未结 4 1570
自闭症患者
自闭症患者 2021-01-04 06:12

I have been reading up on the difference between put and post requests and I have some related questions as it pertains to rails: I would like to change one specific field i

4条回答
  •  孤独总比滥情好
    2021-01-04 06:19

    Rails by default aims to use HTTP verbs in the manner laid out by the REST specification, you should not be concerned as to why the methods may allow you to carry out the same action. Instead you should think about providing an API that is RESTful and that users will understand. These default behaviour can be overridden.

    REST denotes that:

    A request using the POST method should act upon the resource collection; adding a new resource to the collection Example URL: http://example.com/resources

    A request using the PUT HTTP verb should act upon a single resource within the collection; replacing the resource wholly upon the server Example URL: http://example.com/resource/1

    A request using the PATCH HTTP verb should act upon a single resource within the collection; updating certain attributes upon the resource where it stands Example URL: http://example.com/resource/1

    Rails 4 now makes use of the PATCH verb over the PUT verb for updating a resource.

提交回复
热议问题