哪种HTTP方法与哪种CRUD方法匹配? [英] Which HTTP methods match up to which CRUD methods?
问题描述
在RESTful样式编程中,我们应该使用HTTP方法作为构建块。虽然哪种方法与经典的CRUD方法相匹配,但我有点困惑。 GET / Read和DELETE / Delete非常明显。
In RESTful style programming, we should use HTTP methods as our building blocks. I'm a little confused though which methods match up to the classic CRUD methods. GET/Read and DELETE/Delete are obvious enough.
然而,PUT / POST有什么区别?它们是否与创建和更新一对一匹配?
However, what is the difference between PUT/POST? Do they match one to one with Create and Update?
推荐答案
Create = PUT with a new URI
POST to a base URI returning a newly created URI
Read = GET
Update = PUT with an existing URI
Delete = DELETE
PUT可以映射到Create和Update,具体取决于PUT使用的URI的存在。
PUT can map to both Create and Update depending on the existence of the URI used with the PUT.
POST映射到Create。
POST maps to Create.
更正:POST也可以映射到Update,尽管它通常用于Create。 POST也可以是部分更新,因此我们不需要建议的PATCH方法。
Correction: POST can also map to Update although it's typically used for Create. POST can also be a partial update so we don't need the proposed PATCH method.
这篇关于哪种HTTP方法与哪种CRUD方法匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!