Comprehensive Guide to HTTP Request Methods

Comprehensive Guide to HTTP Request Methods

The HyperText Transfer Protocol (HTTP) is a stateless protocol that operates at the transport layer of the OSI seven-layer model. The HTTP client constructs appropriate HTTP request methods as needed, while the HTTP server responds differently based on various HTTP request methods.

1. HTTP Versions and HTTP Request Methods

Throughout the development of HTTP, many versions have emerged, most of which are backward compatible. When making an HTTP request, the client informs the server of the protocol version being used, and the server responds using the same or an earlier version of the protocol.

HTTP/0.9

This is the earliest version of HTTP that was widely used and is now obsolete. In this version, there is only one request method, <span>GET</span>, and HTTP communication does not specify a version number nor support request header information. This version does not support methods like <span>POST</span>, so the client’s ability to pass information to the server is very limited. A request in <span>HTTP/0.9</span> consists of just one line:

GET www.itbilu.com

HTTP/1.0

This version was the first to specify the version number in HTTP communication. <span>HTTP/1.0</span> is still widely used today, especially in proxy servers.

<span>HTTP/1.0</span> supports three HTTP request methods: <span>GET</span>, <span>POST</span>, and <span>HEAD</span>.

HTTP/1.1

<span>HTTP/1.1</span> is the currently used version. This version defaults to persistent connections and works well with proxy servers. It also allows multiple requests to be sent simultaneously in a pipelined manner to reduce line load and increase transmission speed.

<span>HTTP/1.1</span> introduced five new HTTP request methods: <span>OPTIONS</span>, <span>PUT</span>, <span>DELETE</span>, <span>TRACE</span>, and <span>CONNECT</span>.

HTTP/2

This version is the latest released version, officially published in May of this year (May 2015). <span>HTTP/2</span> reduces latency by supporting multiplexing of requests and responses while minimizing protocol overhead by compressing HTTP header fields, and it also adds support for request prioritization and server push.

2. Introduction to HTTP Request Methods

<span>HTTP/1.1</span> defines a total of eight HTTP request methods, which are also known as “request actions.” Different methods specify different ways of interacting with the designated resources. The server also responds differently based on the request method.

GET

<span>GET</span> requests will <span>display</span> the specified resource. Generally, the <span>GET</span> method should only be used for data retrieval and not for operations that could produce side effects, which are <span>non-idempotent</span> actions.

<span>GET</span> requests the specified page information and returns the response body. The <span>GET</span> method is considered unsafe because <span>GET</span> requests can be accessed by web crawlers and others.

HEAD

<span>HEAD</span> method is similar to the <span>GET</span> method, as it also requests the specified resource from the server. However, the server does not return the content portion of the resource in response to a <span>HEAD</span> request, i.e., the response body. This allows us to obtain the server’s response header information without transmitting all the content.<span>HEAD</span> method is commonly used for clients to check server performance.

POST

<span>POST</span> requests submit data to the specified resource, requesting the server to process it, such as form data submission or file uploads. The request data is included in the request body.<span>POST</span> method is <span>non-idempotent</span> because this request may create new resources or modify existing ones.

PUT

<span>PUT</span> requests upload the latest content to the specified resource location. The <span>PUT</span> method is <span>idempotent</span>. Through this method, clients can send the latest data of the specified resource to the server, replacing the content of the specified resource.

DELETE

<span>DELETE</span> requests the server to delete the resource identified by the requested <span>URI</span> (Uniform Resource Identifier). After a <span>DELETE</span> request, the specified resource will be deleted, and the <span>DELETE</span> method is also <span>idempotent</span>.

CONNECT

<span>CONNECT</span> method is reserved in the <span>HTTP/1.1</span> protocol to allow a connection to be switched to a tunnel mode for proxy servers. It is typically used for communication between SSL encrypted servers and unencrypted HTTP proxy servers.

OPTIONS

<span>OPTIONS</span> requests are similar to <span>HEAD</span>, and are generally used for clients to check server performance. This method requests the server to return all HTTP request methods supported by that resource. This method uses ‘*’ to replace the resource name. Sending an <span>OPTIONS</span> request to the server can test if the server functions normally. When using the XMLHttpRequest object in JavaScript for <span>CORS</span> (Cross-Origin Resource Sharing), the <span>OPTIONS</span> method is used to send a sniffing request to determine whether access to the specified resource is permitted.

TRACE

<span>TRACE</span> requests the server to echo back the request information it received. This method is mainly used for testing or diagnosing HTTP requests.

Methods Added After HTTP/1.1 have been progressively expanded since the standard was established. Among them, the most commonly used is the <span>PATCH</span> method:

PATCH

<span>PATCH</span> method appeared later and was defined in the RFC 5789 standard in 2010. <span>PATCH</span> requests are similar to <span>PUT</span> requests, and are also used for resource updates. The two have the following differences:

  • However, <span>PATCH</span> is generally used for partial updates of resources, while <span>PUT</span> is generally used for complete updates of resources.

  • When a resource does not exist, <span>PATCH</span> will create a new resource, while <span>PUT</span> will only update an existing resource.

Comprehensive Guide to HTTP Request Methods

Comprehensive Guide to HTTP Request Methods

Leave a Comment