The method of HTTP request: GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE described
The usual Rest development, use of all GET, POST, PUT, DELETE types of requests.
But Rest supported request types than the previous four kinds, there are several other.
Transfer from the following portion: https://www.html.cn/archives/9341
https://www.cnblogs.com/lnlvinso/p/11000568.html
Hypertext Transfer Protocol (HTTP, HyperText Transfer Protocol) is a stateless protocol, which is located in the OSI model transport layer. HTTP client needed to build the appropriate HTTP request method, and the HTTP server may respond differently depending on the HTTP request method.
1. The method of HTTP request and HTTP version
In the development process of HTTP, there have been many versions of HTTP, which most of the agreements are downward compatible. During HTTP request, the client tells the server when requesting the protocol version it uses, which makes the server using the same or an earlier version of the protocol to respond.
HTTP/0.9
This is the first large-scale use of HTTP version, is now obsolete. In this version, only GET
one kind of request method, the HTTP communication did not specify a version number, does not support the request header information. This version does not support POST
other methods, so the ability to pass information to the client server is very limited. HTTP/0.9
Requested is the following line:
GET www.itbilu.com
HTTP/1.0
This version is the first version number specified in the HTTP communication protocol version HTTP/1.0
is still being widely used, especially in the proxy server.
HTTP/1.0
GET
Support: POST
, , HEAD
three kinds of HTTP request methods.
HTTP/1.1
HTTP/1.1
I am currently using version. The default version uses a persistent connection, and can work well with a proxy server. Also supports the pipe simultaneously send multiple requests, in order to reduce line load, increase the transmission speed.
HTTP/1.1
OPTIONS
Added: PUT
, DELETE
, TRACE
, , CONNECT
five kinds of HTTP request methods.
HTTP/2
This version is the latest released version, in May this year (May 2015) to make HTTP standard officially released. HTTP/2
By supporting multiple requests corresponding to a weight to reduce latency, the HTTP header field compression by protocol overhead to a minimum, while increasing the priority of the request and the server-side push support.
2. HTTP request method described
HTTP/1.1
CCP protocol defines eight methods HTTP request, the HTTP request method is also called "requested operation", different methods provide for different ways of operation specified resource. The server will do different responses depending on the request method.
GET
GET
Request will 显示
request the specified resource. General GET
method should be used only for reading data, and should not be used to produce side effects 非幂等
operation.
GET
The method will request the specified page information, and returns the response body, GET
it is considered to be unsafe method, because GET
the method can be any access network spiders.
HEAD
HEAD
Method and GET
method, are specified resource request to the server. However, the server response HEAD
does not return the contents of part of the resource request, namely: the response body. Under such circumstances, we can not transmit the entire contents, you can get the server's response headers. HEAD
The method is often used by the client to view server performance.
POST
POST
Submit a request to the designated resource data, the server processes the request, such as: Submit form data, file upload, etc., request data is contained in the request body. POST
The method is 非幂等
a method, since the request may create new resources and / or modify existing resources.
PUT
PUT
Requests the body to upload their content to the latest specified resource location, PUT
method is 幂等
the method. The latest resource data transfer specified by this method the client to the server can replace the contents of the specified resource.
DELETE
DELETE
Request for requesting the server to delete the requested URI
resources identified (Uniform Resource Identifier uniform resource identifier). DELETE
After the specified resource request is deleted, DELETE
the method also 幂等
is.
CONNECT
CONNECT
The method is HTTP/1.1
protocol reserved, the proxy server can be connected to the pipeline mode. Commonly used in SSL communication link and the non-encrypted encrypted HTTP proxy server.
OPTIONS
OPTIONS
Request HEAD
similar, it is generally used by the client to view server performance. This method will return all HTTP requests that the server supports the requested resource method will use '*' instead of the resource name, the server sends a OPTIONS
request, you can test server functions are normal. JavaScript's XMLHttpRequest object CORS
when cross-domain resource sharing, is to use the OPTIONS
method to send sniffer request to determine whether there is access to the specified resource. allow
TRACE
TRACE
Echo request message requesting the server which receives the HTTP request method is mainly used for test or diagnosis.
HTTP/1.1
After increasing method
In the HTTP/1.1
following standards, and gradually expand a number of ways. Which is in use more PATCH
methods?:
PATCH
PATCH
The method appears later, in 2010, it is RFC 5789 is defined standard. PATCH
Request and PUT
the request is similar to, for updating the same resource. Both the following differences:
- But
PATCH
the general part of the resources for the update, andPUT
overall resources for the general update. - When the resource does not exist,
PATCH
it creates a new resource, andPUT
will only have to update the resource.
Security and Idempotence
These HTTP requests on a method used with two basic characteristics, i.e., "Security" and "idempotent."
For the above seven HTTP methods, GET, HEAD and OPTIONS methods are considered safe because they are designed to achieve access to the data, does not have the "border effect." As for the other four HTTP methods, since they cause a change of server resources, so the method is considered to be unsafe.
Idempotent (the Idempotent) is a mathematical concept, where one indicates a boundary and transmitting multiple requests effect induced is the same. In the case where speed is not fast enough, the client sends a request can not be immediately respond, because if not determine whether the request was successfully submitted, it is possible to send the same request again another, determining the second idempotent a request is valid.
Above three secure HTTP method (GET, HEAD, and OPTIONS) are idempotent method. Since PATCH DELETE request and a specific operation of existing resources, so they are idempotent method. For PUT request, only in the case of a server will add the corresponding resource does not exist, otherwise only for modification operations, so it is also idempotent methods. As for the last POST, because it always add operation, if the server receives the same twice POST operations, will result in two identical resource is created, so this is a non-idempotent methods.
When we were designing the Web API should try to determine the logic processing of the request of the HTTP method of idempotent type. Because PUT is a power and other methods, so carry the same resource PUT request should not cause the change of state resources, if we attach a self-growth in the resource counter indicates the number is modified, it actually undermines the idempotent type.
Statelessness
RESTful state as long as the maintenance of resources, without the need to maintain client state. For it is, each request is new, as it requires a corresponding operation for this request, information need not be recorded down to this request for subsequent processing from the same client requests.
For these two characteristics described above, we RESTful, and they asked us to meet all these features do something, but it is only the stateless asked us what not to do, because HTTP itself is stateless. For example, a web page by obtaining records match the query call Paging Web API. In general, the page navigation has recorded the previous page and the next page of the "previous" and "next" link for presenting the current page. So now there are two ways to achieve return records up and down the page.
- Web API will not only define actions based on the specific data query definition of the relevant page, but also define a separate operation for such a request "Previous" and "Next." Its own will on the page every time the returned data is saved locally according to the client Session ID, in order to be able to know specifically what the previous and next page.
- Web API will define actions based on the specific data query definition of the relevant page, the current page number to return data from the client to maintain.
The first looks like a very "smart", is actually a superfluous practice, because it undermines the stateless nature of the Web API. Design stateless Web API Web API not only make themselves look simple and refined, but also because of the deduction for the client's "affinity (Affinty)" so that we can effectively implement load balancing, because the only way the cluster each server for each client is equivalent.
The usual Rest development, use of all GET, POST, PUT, DELETE types of requests.
But Rest supported request types than the previous four kinds, there are several other.
Transfer from the following portion: https://www.html.cn/archives/9341
https://www.cnblogs.com/lnlvinso/p/11000568.html
Hypertext Transfer Protocol (HTTP, HyperText Transfer Protocol) is a stateless protocol, which is located in the OSI model transport layer. HTTP client needed to build the appropriate HTTP request method, and the HTTP server may respond differently depending on the HTTP request method.
1. The method of HTTP request and HTTP version
In the development process of HTTP, there have been many versions of HTTP, which most of the agreements are downward compatible. During HTTP request, the client tells the server when requesting the protocol version it uses, which makes the server using the same or an earlier version of the protocol to respond.
HTTP/0.9
This is the first large-scale use of HTTP version, is now obsolete. In this version, only GET
one kind of request method, the HTTP communication did not specify a version number, does not support the request header information. This version does not support POST
other methods, so the ability to pass information to the client server is very limited. HTTP/0.9
Requested is the following line:
GET www.itbilu.com
HTTP/1.0
This version is the first version number specified in the HTTP communication protocol version HTTP/1.0
is still being widely used, especially in the proxy server.
HTTP/1.0
GET
Support: POST
, , HEAD
three kinds of HTTP request methods.
HTTP/1.1
HTTP/1.1
I am currently using version. The default version uses a persistent connection, and can work well with a proxy server. Also supports the pipe simultaneously send multiple requests, in order to reduce line load, increase the transmission speed.
HTTP/1.1
OPTIONS
Added: PUT
, DELETE
, TRACE
, , CONNECT
five kinds of HTTP request methods.
HTTP/2
This version is the latest released version, in May this year (May 2015) to make HTTP standard officially released. HTTP/2
By supporting multiple requests corresponding to a weight to reduce latency, the HTTP header field compression by protocol overhead to a minimum, while increasing the priority of the request and the server-side push support.
2. HTTP request method described
HTTP/1.1
CCP protocol defines eight methods HTTP request, the HTTP request method is also called "requested operation", different methods provide for different ways of operation specified resource. The server will do different responses depending on the request method.
GET
GET
Request will 显示
request the specified resource. General GET
method should be used only for reading data, and should not be used to produce side effects 非幂等
operation.
GET
The method will request the specified page information, and returns the response body, GET
it is considered to be unsafe method, because GET
the method can be any access network spiders.
HEAD
HEAD
Method and GET
method, are specified resource request to the server. However, the server response HEAD
does not return the contents of part of the resource request, namely: the response body. Under such circumstances, we can not transmit the entire contents, you can get the server's response headers. HEAD
The method is often used by the client to view server performance.
POST
POST
Submit a request to the designated resource data, the server processes the request, such as: Submit form data, file upload, etc., request data is contained in the request body. POST
The method is 非幂等
a method, since the request may create new resources and / or modify existing resources.
PUT
PUT
Requests the body to upload their content to the latest specified resource location, PUT
method is 幂等
the method. The latest resource data transfer specified by this method the client to the server can replace the contents of the specified resource.
DELETE
DELETE
Request for requesting the server to delete the requested URI
resources identified (Uniform Resource Identifier uniform resource identifier). DELETE
After the specified resource request is deleted, DELETE
the method also 幂等
is.
CONNECT
CONNECT
The method is HTTP/1.1
protocol reserved, the proxy server can be connected to the pipeline mode. Commonly used in SSL communication link and the non-encrypted encrypted HTTP proxy server.
OPTIONS
OPTIONS
Request HEAD
similar, it is generally used by the client to view server performance. This method will return all HTTP requests that the server supports the requested resource method will use '*' instead of the resource name, the server sends a OPTIONS
request, you can test server functions are normal. JavaScript's XMLHttpRequest object CORS
when cross-domain resource sharing, is to use the OPTIONS
method to send sniffer request to determine whether there is access to the specified resource. allow
TRACE
TRACE
Echo request message requesting the server which receives the HTTP request method is mainly used for test or diagnosis.
HTTP/1.1
After increasing method
In the HTTP/1.1
following standards, and gradually expand a number of ways. Which is in use more PATCH
methods?:
PATCH
PATCH
The method appears later, in 2010, it is RFC 5789 is defined standard. PATCH
Request and PUT
the request is similar to, for updating the same resource. Both the following differences:
- But
PATCH
the general part of the resources for the update, andPUT
overall resources for the general update. - When the resource does not exist,
PATCH
it creates a new resource, andPUT
will only have to update the resource.
Security and Idempotence
These HTTP requests on a method used with two basic characteristics, i.e., "Security" and "idempotent."
For the above seven HTTP methods, GET, HEAD and OPTIONS methods are considered safe because they are designed to achieve access to the data, does not have the "border effect." As for the other four HTTP methods, since they cause a change of server resources, so the method is considered to be unsafe.
Idempotent (the Idempotent) is a mathematical concept, where one indicates a boundary and transmitting multiple requests effect induced is the same. In the case where speed is not fast enough, the client sends a request can not be immediately respond, because if not determine whether the request was successfully submitted, it is possible to send the same request again another, determining the second idempotent a request is valid.
Above three secure HTTP method (GET, HEAD, and OPTIONS) are idempotent method. Since PATCH DELETE request and a specific operation of existing resources, so they are idempotent method. For PUT request, only in the case of a server will add the corresponding resource does not exist, otherwise only for modification operations, so it is also idempotent methods. As for the last POST, because it always add operation, if the server receives the same twice POST operations, will result in two identical resource is created, so this is a non-idempotent methods.
When we were designing the Web API should try to determine the logic processing of the request of the HTTP method of idempotent type. Because PUT is a power and other methods, so carry the same resource PUT request should not cause the change of state resources, if we attach a self-growth in the resource counter indicates the number is modified, it actually undermines the idempotent type.
Statelessness
RESTful state as long as the maintenance of resources, without the need to maintain client state. For it is, each request is new, as it requires a corresponding operation for this request, information need not be recorded down to this request for subsequent processing from the same client requests.
For these two characteristics described above, we RESTful, and they asked us to meet all these features do something, but it is only the stateless asked us what not to do, because HTTP itself is stateless. For example, a web page by obtaining records match the query call Paging Web API. In general, the page navigation has recorded the previous page and the next page of the "previous" and "next" link for presenting the current page. So now there are two ways to achieve return records up and down the page.
- Web API will not only define actions based on the specific data query definition of the relevant page, but also define a separate operation for such a request "Previous" and "Next." Its own will on the page every time the returned data is saved locally according to the client Session ID, in order to be able to know specifically what the previous and next page.
- Web API will define actions based on the specific data query definition of the relevant page, the current page number to return data from the client to maintain.
The first looks like a very "smart", is actually a superfluous practice, because it undermines the stateless nature of the Web API. Design stateless Web API Web API not only make themselves look simple and refined, but also because of the deduction for the client's "affinity (Affinty)" so that we can effectively implement load balancing, because the only way the cluster each server for each client is equivalent.