HTTP methods

The method that is the first word in the status line of the request tells the server what to do with the request. The standard defines different methods, such as GET, HEAD, POST, PUT, DELETE, and some others.

The client uses the GET method when it wants to get the content of a resource. In the case of a GET request, the body of the request is empty. This is the method used by the browser when we download a web page. It is also, many times, the method used when some program implemented in JavaScript and running in the browser asks for some information from a web application, but it does not want to send much information to the server.

When the client uses POST, the intention is usually to send some data to the server. The server does reply and, many times, there is also a body in the reply, but the main purpose of the request/reply communication is to send some information from the client to the server. This is the opposite of the GET method in some sense.

The GET and POST methods are the most frequently used methods. Although there is a general guideline to use GET to retrieve data and POST to send data to the server, it is only a recommendation, and there is no clean separation of the two cases. Many times, GET is used to send some data to the server. After all, it is an HTTP request with a status line and header fields, and although there is no body in the request, the object (part of the URL) that follows the method in the status line is still able to deliver parameters. Many times, it is also easy to test a service that responds to a GET request because you only need a browser and to type in the URL with the parameters, and look at the response in the browser developer tools. You should not be surprised if you see an application that uses GET requests to execute operations that modify the state on a web server. However, not being surprised does not mean approval. You should be aware that in most cases, these are not good practices. When we send sensitive information using the GET request, the parameters in the URL are available to the client in the address line of the browser. When we send using POST, the parameters are still reachable by the client (after all, the information the client sends is generated by the client and, as such, cannot be unavailable), but not that easy for a simple security-unaware user to copy-paste the information and send, perhaps, to a malevolent third party. The decision between using GET and POST should always consider practicalities and security issues.

The HEAD method is identical to a GET request, but the response will not contain a body. This is used when the client is not interested in the actual response. It may happen that the client already has the object and wants to see if it was changed. The Last-Modified header will contain the time when the resource was last changed, and the client can decide if it has a newer one or needs to ask for the resource in a new request.

The PUT method is used when the client wants to store something on the server and DELETE when the client wants to erase some resource. These methods are used only by applications usually written in JavaScript and not directly by the browser.

There are other methods defined in the standard, but these are the most important and frequently used ones.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.51.153