4.1 List of HTTP Methods

The very first word in an HTTP request is the method name . There is even some analogy with calling methods in Java. The method in the HTTP request defines the basic operation to be performed on the resource.

What kind of resource? The thing is that at the dawn of the World Wide Web, servers simply stored HTML files, respectively, the request was for such a file and described some action that needs to be performed with the resource / file.

The HTTP standard specifies the following methods:

# Method Description
1 GET Used to query the contents of the specified resource.
2 POST Used to transfer data from the client to the server. Changes the state of a resource on the server.
3 PUT Used to transfer data from the client to the server. Creates a new resource on the server.
4 DELETE Deletes the specified resource on the server.
5 HEAD Similar to GET, but there is no response body. Required to get response headers
6 OPTIONS Requests the server for a list of supported methods for the specified resource.
7 TRACE service method. Allows you to find out if the request is being changed by the servers through which it passes.
8 CONNECT service method. Used to establish a secure connection.

4.2 GET method

The GET method is the most popular HTTP method. This is what the browser calls when it sends a request to the server for the next page.

For example, if you followed the link http://codegym.cc/path/resource?param1=value1¶m2=value2 in the browser, then the browser will send an HTTP request to the CodeGym server that will begin with this starting line :

GET /path/resource?param1=value1&param2=value2 HTTP/1.1

As a result, the server will have to send an HTTP response to the browser, in which to write the status of the request, and also send the requested resource.

It is assumed that calling the GET method multiple times does not change the state of the server, and the server must return the same response each time . Therefore, the protocol has a tricky control over object caching.

Firstly, the resources received using the GET request, the browser can cache on its side at its discretion (there are nuances).

Secondly, when sending a request to the server, you can specify a special header If-Modified-Sinceand date. If the requested resource/document has changed since the specified date, then the server will send it. If not changed, then the resource body is not passed. It is assumed that it is cached on the client.

Page caching (GET requests) is used all the time, so I advise you to look into this issue.

4.3 POST and PUT Methods

The POST method is used to update a resource on the server. For example, when you upload an image to the server, your browser sends a POST request.

Consider an HTTP request that will start with this starting line:

POST /path/resource?param1=value1&param2=value2 HTTP/1.1
headers…

<request body>

As a result, the server will have to send an HTTP response to the browser, in which it will write the status of the request, and also send the modified resource. Calling the POST method multiple times changes the state of the server and the server may return a different response each time .

GET and POST are the two most common requests on the web. To make it easier for you to remember how the methods work, consider the following table:

GET POST PUT
Request URL only URL and request body URL and request body
Answer Response code and body Response code and body Response code

You can read more about the POST request at the link .

4.4 DELETE method

And finally, information on the DELETE method . Everything is simple here.

For example, we want to delete a certain resource on the server. We send him a request like:

DELETE  /path/resource?param1=value1&param2=value2 HTTP/1.1

Upon receiving this request, the server will delete the specified resource. Unless, of course, you have the rights to delete it.