PUT和PATCH都是更新资源,而PATCH用来对已知资源进行局部更新。
比如我们有一篇文章的地址https://www.jianshu.com/articles/820357430,这篇文章的可以表示为:
article = {
author: 'dxy',
creationDate: '2019-6-12',
content: '我写文章像蔡徐坤',
id: 820357430
}
当我们要修改文章的作者时,我们可以直接发送PUT https://www.jianshu.com/articles/820357430,这个时候的数据应该是:
{
author:'蔡徐坤',
creationDate: '2019-6-12',
content: '我写文章像蔡徐坤',
id: 820357430
}
这种直接覆盖资源的修改方式应该用put,但是你觉得每次都带有这么多无用的信息,那么可以发送PATCH https://www.jianshu.com/articles/820357430,这个时候只需要:
{
author:'蔡徐坤',
}