Node.js code for HEAD Request Example
This Node.js code snippet was generated automatically for the HEAD Request example.<< Back to the HEAD Request example
What is HTTP?
HTTP (Hypertext Transfer Protocol) is a data transfer protocol that transfers data between an HTTP client (browser or mobile app) and a server. HTTP is built around messages called request and response. The client sends a request to the server, then the server processes this request and sends a response back to the client. Each HTTP message consists of a request/response line, HTTP headers, and a message body.
What is the HEAD request method used for?
The HTTP HEAD method is one of 9 commonly used Hypertext Transfer Protocol (HTTP) request methods. It is used to retrieve HTTP headers from the server. An HTTP HEAD request is made before loading a large resource to check resource size, validity, accessibility, and recent modification time. HTTP HEAD requests cannot have a message body. The HTTP HEAD method is defined as idempotent, which means that multiple identical HEAD requests should have the same effect as a single request.
Basic HEAD Request Example
The following is an example of sending the HEAD request to the ReqBin echo URL:
How to send HTTP headers using the HEAD method?
You can send any HTTP headers along with the HEAD request. For example, you can send additional information about your browser or mobile application or send user authentication credentials in the headers. By default, browsers send the User-Agent, Accept, Accept-Encoding, and Referer HTTP headers on every HEAD and GET request.
Can I send data using the HEAD method?
HTTP HEAD requests cannot have a message body, but it is possible to send data to the server using URL parameters. However, keep in mind that the maximum URL size will be limited to about 2000 characters (depending on the browser) and that this method is not suitable for transferring sensitive data.
What is the difference between the HEAD and GET request methods?
The main difference between HTTP HEAD and GET requests is that for a HEAD request, the server only returns headers without a response body, but specifies the size of the response content using the Content-Length header. The HEAD method is faster than the HTTP GET method because less data is transferred in HEAD requests.