请求方法
HTTP 请求方法
本文着眼于讨论
Get 与Post
Post 与Put
注意到,
POST /articles HTTP/1.1
{
"author": "ethan",
"title": "hello world",
"content": "hello world"
}
在上面,
HTTP/1.1 201 Created
Location: /articles/abcdef123
我们如果知道新建资源的标识符,可以使用
PUT /articles/abcdef234 HTTP/1.1
{
"author": "peter",
"title": "hello world",
"content": "hello world"
}
在上面,/articles/abcdef234
,它指明了资源的存放位置,如果资源被成功创建,服务器可以返回 201 Created
状态以及新建资源的位置,比如:
HTTP/1.1 201 Created
Location: /articles/abcdef234
- 使用
PUT 更新某一资源,需要更新资源的全部属性;而使用POST ,可以更新全部或一部分值
比如使用/articles/abcdef234
的文章的标题,我们需要发送所有值:
PUT /articles/abcdef234 HTTP/1.1
{
"author": "peter",
"title": "hello python",
"content": "hello world"
}
而使用
POST /articles/abcdef234 HTTP/1.1
{
"title": "hello python"
}