REST verbs - which convention is “correct”

前端 未结 7 2438
有刺的猬
有刺的猬 2020-12-25 13:20

I\'m well into implementing a REST service (on a Windows CE platform if that matters) and I started out using IBM\'s general definitions of using POST for creating (INSERTs)

7条回答
  •  天命终不由人
    2020-12-25 13:58

    The reason to use POST as INSERT and PUT as UPDATE is that POST is the only nonidempotent and unsafe operation according to HTTP. Idempotent means that no matter how many times you apply the operation, the result is always the same. In SQL INSERT is the only nonidempotent operation so it should be mapped onto POST. UPDATE is idempotent so it can be mapped on PUT. It means that the same PUT/UPDATE operation may be applied more than one time but only first will change state of our system/database.

    Thus using PUT for INSERT will broke HTTP semantic viz requirement that PUT operation must be idempotent.

提交回复
热议问题