The HTTP request method

commonly used ways:


  1. get

  2. head

    Server entity does not return the requested data, only returns response headers.

    It can be seen as a simplified version of the get method "or" lightweight version ", since it is identical to get response header.

    Can be used in many occasions not really need resources, avoiding waste transport body data.

    Scene 1: To check whether a file exists, as long as you can send a HEAD request, no need to use GET to take down the entire file.

    Scene 2: To check if a file with the latest version, you should use HEAD, the server will transfer the file modification time back in the response in advance.

  3. post

  4. put

    If the post is new, then put can be understood as modified

  5. delete

    Instructs the server to delete the resource.

    Because this action too dangerous, it is usually the server does not perform the actual deletion, but for the resources to do a delete mark.


It can be used to describe CRUD:

insert:post

delete:delete

update:put

select:get


safety:

The so-called "security" means the request method will not "destroy" resources on the server, that does not cause substantial changes to the resources on the server.

get, head is safe because it is read-only.

post, put, delete unsafe.


Idempotent:

Number of "power" after the result is "equal." Repeatedly perform the same operation, the results are the same.

get, head idempotent.

Every post is equivalent to new, so it is not idempotent.

put each modification can be understood as the same data is, it is idempotent.

delete can be deleted for the same data multiple times, the effect is "resource does not exist", it is also idempotent.



Guess you like

Origin blog.51cto.com/11009785/2448626