http action PUT POST使用的時機
Some considerations:
- Do you name your URL objects you create explicitly, or let the server decide? If you name them then use PUT. If you let the server decide then use POST.
- PUT is idempotent, so if you PUT an object twice, it has no effect. This is a nice property, so I would use PUT when possible.
- You can update or create a resource with PUT with the same object URL
- With POST you can have 2 requests coming in at the same time making modifications to a URL, and they may update different parts of the object.
/*
idempotent 的意思是如果相同的操作再執行第二遍第三遍,結果還是一樣。
根據 HTTP 的規格,GET, HEAD, PUT 和 DELETE 是 idempotent
只有 POST 和 PATCH 不是 idempotent
*/
1.若該物件為自定義傳輸的則為PUT, 由server決定則是POST
2.PUT是idempotent(冪等),若重新PUT兩次則沒有影響
3.PUT可以更新以及新增,只需使用同一個URL
4.POST可以同時接受多筆request進入並修改不同處
留言
張貼留言