⚠️ This lesson is retired and might contain outdated information.

Use HTTP GET & HEAD Methods

Pete Johanson
InstructorPete Johanson

Share this video with your friends

Send Tweet
Published 7 years ago
Updated 10 months ago

The HTTP GET & HEAD methods are used to retrieve information about a resource. The GET method will retrieve the metadata about the resource, encoded in the HTTP headers, as well as a representation of the resource itself in the message body (e.g. a JSON document with fields that describe a user). The HEAD method behaves like GET, but only retrieves the status and headers; this can be useful when you need some metadata about a resource (e.g. the Last-Modification time), but don't want to waste time or bandwidth fetch the resource itself in the message body. Finally, we discuss the idempotent and safe natures of these HTTP methods.

[00:00] The HTTP get method is used to retrieve a representation of a resource. Let's take a look at my user using the GitHub API. Here we can see the HTTP get has returned us a set of headers with metadata about this particular resource as well as the actual message body containing a representation of that resource, in this case, in JSON format.

[00:30] Much like get, the head HTTP method is used to retrieve a resource. Unlike get, the response will only include the HTTP headers containing the metadata about that resource and does not include the message body.

[00:47] This can be very useful if we need to only look up some metadata about a resource such as whether we have the latest version based on the e-tag or the last modified date of a certain resource and we don't want to waste the bandwidth or time retrieving the actual resource body.

[01:04] Both get and head are considered item potent methods which means that issuing multiple requests or just one request will have the exact same effect. I can issue several head requests of this resource, and there will be no changes made to the resource. The response will be the same.

[01:24] Much like being item potent, both get and head are also considered safe methods. That means that a user agent such as a browser can feel free to resubmit these requests when a user clicks the back button without prompting them or warning them that there may be some changes made as a result of issuing those requests.

[01:44] To summarize, both get and head will retrieve a resource. The main difference being get will also retrieve a representation of the resource in the body in addition to the header's return.

~ 5 years ago

This is gold, thanks!