【Rest】PUT Vs Post in Rest

what is rest

【Rest】PUT Vs Post in Rest_第1张图片
Paste_Image.png
【Rest】PUT Vs Post in Rest_第2张图片
Paste_Image.png

StackOverFlow上的关于Rest put 和post请求的讨论

http://stackoverflow.com/questions/630453/put-vs-post-in-rest?rq=1
--来自stackOverFlow上的关于,post和put请求区别的一场讨论

Use POST to create, and PUT to update. That's how Rails is doing it, anyway.
PUT /items/1 #=> update
POST /items #=> create

PUT
PUT /resources/ HTTP/1.1
PUT /resources/ HTTP/1.1
在原来resourceID下进行Put请求,就是对资源的更新
在新的资源ID下进行PUT请求,则是创建新的资源
POST
Create a new resource under the /resources URI, or collection. Usually the identifier is returned by the server.
--POST /resources HTTP/1.1
--POST在原来的资源ID下添加新的对象

网友的评论:

  • PUT is not for update, it is for replace, note that to create you are replacing nothing with something. POST is absolutely not for update in any shape of form.

--POST is used to create.
--PUT is used to create or update.

  • Both PUT and POST can be used for creating.

你可能感兴趣的:(【Rest】PUT Vs Post in Rest)