What is the GET method?
The primary tool for reading data
Imagine you walk into a restaurant and ask the host to see the menu. You aren't ordering anything or changing anything: you are just requesting information. In the web development world, when a browser asks a server for information, it uses the GET method.
The GET method is the most common HTTP action. Every time you type a URL into your browser and hit Enter, your browser sends a GET request to the server.
Read-only and safe
The most important rule of the GET method is that it is read-only. It should only be used to retrieve data, never to create, update, or delete data. Because GET requests don't change the server's state, they are considered "safe" methods.
# This is safe - just fetching data
[Client] -> "GET /articles/1" -> [Server]
[Client] <- "HTML of Article" <- [Server]
The concept of idempotency
GET requests are idempotent. This is a fancy word meaning that if you make the same request once or one hundred times, the state of the server remains the same. Reading a blog post over and over again doesn't change the content of the blog post.
Summary
| Concept | Key Point |
|---|---|
| Purpose | Retrieve data from the server |
| Safe | Does not modify data (read-only) |
| Idempotent | Repeating the request has the same effect as making it once |
| Usage | Typing a URL in a browser sends a GET request |
Keep going with lesson 2
Anatomy of a GET request
Shows how a GET request carries everything in the URL and headers, since it has no body.
A free account also gives you the quizzes, your progress and notes, and the discussion.