Why do we need anything more than HTTP GET, PUT, POST?

后端 未结 14 770
-上瘾入骨i
-上瘾入骨i 2021-02-04 10:09

What is the practical benefit of using HTTP GET, PUT, DELETE, POST, HEAD? Why not focus on their behavioral benefits (safety and idempotency), forgetting their names, and use GE

14条回答
  •  温柔的废话
    2021-02-04 10:23

    In a word:

    idempotency

    In a few more words:

    GET = safe + idempotent

    PUT = idempotent

    DELETE = idempotent

    POST = neither safe or idempotent

    'Idempotent' just means you can do it over and over again and it will always do exactly the same thing.

    You can reissue a PUT (update) or DELETE request as many times as you want and it will have the same effect every time, however the desired effect will modify a resource so it is not considered 'safe'.

    A POST request should create a new resource with every request, meaning the effect will be different every time. Therefore POST is not considered safe or idempotent.

    Methods like GET and HEAD are just read operations and are therefore considered 'safe' aswell as idempotent.

    This is actually a pretty important concept because it provides a standard/consistent way to interpret HTTP transactions; this is particularly useful in a security context.

提交回复
热议问题