RestApi中PUT,POST,PATCH的区别

1. POST

1. POST to a URL creates a child resource at a server defined URL. 

2. POST creates a child resource, so POST to /items creates a resources that lives under the /items resource. Eg. /items/1. Sending the same post packet twice will create two resources.

2. POST

1. PUT to a URL creates/replaces the resource in its entirety at the client defined URL.

2. PUT is for creating or replacing a resource at a URL known by the client.Therefore: PUT is only a candidate for CREATE where the client already knows the url before the resource is created. Eg. /blogs/nigel/entry/when_to_use_post_vs_put as the title is used as the resource key

3. PATCH

1. PATCH to a URL updates part of the resource at that client defined URL. The relevant specification for PUT and POST is RFC 2616 §9.5ff.

2. PUT replaces the resource at the known url if it already exists, so sending the same request twice has no effect. In other words, calls to PUT are idempotent.

Reference

https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5

https://stackoverflow.com/questions/630453/put-vs-post-in-rest/2590281#2590281

转载于:https://my.oschina.net/iak1001/blog/2254532

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值