HTTP方法--Put 还是 Patch?

PUT用于替换特定URI下的文件或资源,如果该位置已有资源则替换,没有则创建,且PUT操作是幂等的。POST则是在指定URI发送数据,由服务器决定如何处理,非幂等,但响应可缓存。PUT适用于整体更新,PATCH适用于部分更新。
摘要由CSDN通过智能技术生成

下面这四个就不需要解释了:
POST = 新增
GET = 读取
PUT = 更新
DELETE = 刪除

POST or PUT?

PUT puts a file or resource at a specific URI, and exactly at that URI. If there’s already a file or resource at that URI, PUT replaces that file or resource. If there is no file or resource there, PUT creates one. PUT is idempotent, but paradoxically PUT responses are not cacheable.

POST sends data to a specific URI and expects the resource at that URI to handle the request. The web server at this point can determine what to do with the data in the context of the specified resource. The POST method is not idempotent, however POST responses are cacheable so long as the server sets the appropriate Cache-Control and Expires headers.

应用:
POST:- Used when the client is sending information or data to the server—for example, filling out an online form (i.e. Sends a large amount of complex data to the Web Server).

PUT:- Used when the client is sending a replacement document or uploading a new document to the Web server under the request URL.

PUT or PATCH?
PUT replace the ENTIRE RESOURCE with the new representation provided (no mention of related resources in the spec from what i can see)

PATCH replace parts of the source resource with the values provided AND|OR other parts of the resource are updated that you havent provided (timestamps) AND|OR updating the resource effects other resources (relationships)

通俗讲,全部更新和局部更新。

put与patch比也不是一无是处:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一苇渡江694

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值