According to the RFC Put
is used to update an existing resource.
但是,Stripe API 使用 Post
更新对象。为什么是这样?
例如,在 Stripe Node Library
update: stripeMethod({
method: 'POST',
path: '{id}',
}),
update
method电话POST
我知道没有Patch
方法,因为每次调用都必须发送整个资源,为什么是 Put
在那种情况下不使用 HTTP 动词?(与来自 an SO question about the Facebook API 的示例不同,资源可以通过 URL 中传递的单个 ID 进行标识)例如 URL 只是
/v1/customers/:id
最佳答案
有趣的问题!来自 your link :
The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. [emphasis mine]
这意味着您必须
PUT
整个资源(变化和非变化)。很少有 API 是这样设计的。来自 spec for POST :
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
- Annotation of existing resources;
许多/大多数 API 已采用
POST
作为更新对象的方式。这里有一些额外的想法:https://stackoverflow.com/a/25909372/379538
关于api - 为什么 Stripe 使用 Post 方法来更新资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64796417/