Is PUT/DELETE idempotent with REST automatic?

前端 未结 3 978
时光说笑
时光说笑 2021-01-30 14:32

I am learning about REST and PUT/DELETE, I have read that both of those (along with GET) is idempotent meaning that multiple requests put the server into the same state.

3条回答
  •  余生分开走
    2021-01-30 14:55

    Does a duplicate PUT/DELETE request ever leave the web browser (when using XMLHttpRequest)?

    Yeah, sure. Idempotence is only a convention and it's not enforced. If you make a request, duplicate or not, it will run through.

    In other words, will the server be updating the same database record for each PUT request, or will duplicate requests be ignored automatically?

    If it conforms to REST it should update the same database record twice, for example running UPDATE user SET name = 'John' twice. There is not guarantee what it will or will not do though, it depends on how it's implemented.

    If yes, how is using PUT or DELETE different from just using POST?

    It's just a convention. PUT and DELETE requests may or may not be handled differently from POST in the site's code.

    I read an article which suggested that RESTful web services were the way forward. Is there any particular reason why HTML5 forms do not support PUT/DELETE methods?

    I'm not really sure, to be honest. You can work around this by using a hidden field called _method or similar and set it to DELETE or PUT, and then handle that server side.

提交回复
热议问题