哪些 HTTP 方法与哪些 CRUD 方法匹配? [英] Which HTTP methods match up to which CRUD methods?

查看:18
本文介绍了哪些 HTTP 方法与哪些 CRUD 方法匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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 也可以映射到更新,尽管它通常用于创建.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆