REST中的PUT与POST

妖精的绣舞 提交于 2020-07-29 05:55:14

问题:

According to the HTTP/1.1 Spec: 根据HTTP / 1.1规范:

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方法用于请求源服务器接受请求中包含的实体作为Request-Line Request-URI标识的资源的新下属

In other words, POST is used to create . 换句话说, POST用于创建

The PUT method requests that the enclosed entity be stored under the supplied Request-URI . PUT方法请求将封闭的实体存储在提供的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. 如果Request-URI引用了已经存在的资源,则应将封闭的实体视为驻留在原始服务器上的实体的修改版本。 If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI." 如果Request-URI没有指向现有资源,并且请求用户代理能够将该URI定义为新资源,则原始服务器可以使用该URI创建资源。”

That is, PUT is used to create or update . 也就是说, PUT用于创建或更新

So, which one should be used to create a resource? 那么,应该使用哪一个来创建资源? Or one needs to support both? 还是需要同时支持两者?


解决方案:

参考一: https://stackoom.com/question/2e0b/REST中的PUT与POST
参考二: https://oldbug.net/q/2e0b/PUT-vs-POST-in-REST
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!