GET
HTTP method
Specification of the HTTP method GET
The GET method requests transfer of a current selected representation for the target resource. GET is the primary mechanism of information retrieval and the focus of almost all performance optimizations. Hence, when people speak of retrieving some identifiable information via HTTP, they are generally referring to making a GET request.
It is tempting to think of resource identifiers as remote file system pathnames and of representations as being a copy of the contents of such files. In fact, that is how many resources are implemented (see Section 9.1 for related security considerations). However, there are no such limitations in practice. The HTTP interface for a resource is just as likely to be implemented as a tree of content objects, a programmatic view on various database records, or a gateway to other information systems. Even when the URI mapping mechanism is tied to a file system, an origin server might be configured to execute the files with the request as input and send the output as the representation rather than transfer the files directly. Regardless, only the origin server needs to know how each of its resource identifiers corresponds to an implementation and how each implementation manages to select and send a current representation of the target resource in a response to GET.
A client can alter the semantics of GET to be a "range request", requesting transfer of only some part(s) of the selecte representation, by sending a Range header field in the request ([RFC7233]).
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
The response to a GET request is cacheable; a cache MAY use it to satisfy subsequent GET and HEAD requests unless otherwise indicated by the Cache-Control header field (Section 5.2 of [RFC7234]).
Description of the GET method
The GET method of the HTTP protocol is comparable to a digital librarian. It politely asks the server to present data without making any changes to the data itself – a purely passive request.
What makes the GET method special?
- Consistency: Imagine asking the librarian for the same book multiple times – you would get the same book each time. The same applies to the GET request: it consistently delivers the same result.
- Read, don't write: The GET request has the character of an observer. It looks at data but doesn't change it.
- Information in the URL: Think of the URL as an address or an index card. It indicates which book or information you are looking for. However, caution: these cards shouldn't contain private notes, as they can be viewed by others.
- Fast and efficient responses: Thanks to the ability to cache responses, the GET method can quickly respond to repeated requests, much like a well-organized librarian who knows exactly where each book is located.
But there are also limitations:
- Limited space for notes: The URL only has so much space for information. It's like writing on a small index card.
- No secrets: Since URLs are visible and can be stored, you shouldn't note down any sensitive information on them.
- No interference: An observer doesn't influence what they observe. Therefore, the GET method should not be used to modify data. There are other tools in our digital toolbox for that.
Overall, the GET method is a reliable and essential tool in the digital space, helping us retrieve information efficiently and safely.
Example of HTTP method GET
GET /data HTTP/1.1
Host: api.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/58.0.3029.110 Safari/537
Accept: application/json
Accept-Language: de-DE,de;q=0.5
Connection: keep-alive
Cache-Control: max-age=0
Content-Type: application/json
Date: Mon, 31 July 2023 14:58:12 GMT
Server: Apache/2.4.7 (Ubuntu)
Cache-Control: no-cache