【Rest】PUT Vs Post in Rest

weixin_34402408發表於2016-01-28

what is rest

1307647-1d5943b60dd3f076.png
Paste_Image.png
1307647-3ba3bc176dac3938.png
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/<existingResourceId> HTTP/1.1
PUT /resources/<newResourceId> 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.

相關文章