为什么 Stripe 使用 Post 方法来更新资源

Why does Stripe use the Post method for updating resources

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, the resource is identifiable by a single ID that is passed in the URL) eg the URL is simply /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;

Many/most API 已采用 POST 作为更新对象的方式。

这里有一些额外的想法: