Is REST DELETE really idempotent?

后端 未结 8 2322
一生所求
一生所求 2020-11-30 18:43

DELETE is supposed to be idempotent.

If I DELETE http://example.com/account/123 it\'s going to delete the account.

If I do it again would I expect a 404, sin

8条回答
  •  囚心锁ツ
    2020-11-30 19:05

    Suppose we have to manage football teams represented by id, name, city.

    {
        id: "1",
        name: "manchester united",
        city : "manchester "
    }
    

    Saying that Delete is idempotent means that if you invoque DELETE /team/1 several time the state of the system stay unchanged (in fact the first call DELETE /team/1 delete the team. In other words, delete is idempotent because duplicated call let the state of system unchanged.

    In the same way we can say PUT also is idempotent. imagine you do this PUT more than once :

    PUT /team/1
    {
            id: "1",
            name: "liverpool",
            city : "liverpool"
    }
    

    Duplicated calls of such PUT request always have the same effect (the team 1 will be liverpool).

    It is obvious that GET requests are idempotent also.

提交回复
热议问题