How HTTP Methods Work
When Web clients send requests, the first line is the Request-Line and it looks like this:
GET / HTTP/2
The word GET is the HTTP method or verb. There are several different methods or actions that can appear there.
Operating on Stored Data with CRUD
There are a few common operations that are done on stored data, with the acronym CRUD:
- Create
- Read
- Update
- Delete
Imagine that you have a database of employees. You could create an employee record, read an employee record, update or edit an employee record, or delete an employee record.
HTTP methods are different from CRUD, but understanding similarities with the basic CRUD pattern might help make some programming concepts fall into place later.
Interacting with resources on the Web is similar to CRUD in that you can create, read, update, and delete content with HTTP. The most common method on the Web is read (GET), but you can also create (POST), update (PUT and PATCH), and delete (DELETE) things (like comments, blog posts, and orders at online stores).
The HTTP Methods
The Request-Line contains the name of the HTTP method or verb that indicates the kind of action being performed.
In this example it’s a POST request:
POST /comment.php HTTP/2
Here’s a sample GET request:
GET /about.html HTTP/2
Create
If you were posting new information on a website with a comment form, the HTTP method there would be POST, because you’re creating something.
Read
The most common kind of request is to read or look at a page or image. The HTTP method is GET.
Update
When content is updated, the method is PUT or PATCH.
(PUT is meant to overwrite an existing record with the payload, while PATCH is mean to update it.)
Delete
When content is deleted, the method is DELETE.
Other HTTP Methods
There are other HTTP methods that are less important for SEO:
HEADTRACEOPTIONSCONNECT
We won’t go into them here, but if you want to read more, check out MDN.
The Default GET Request
A browser’s address bar can only make GET requests. Those requests get information from the server without changing anything on the server.
Form Data
HTML forms (and JavaScript) allow browsers to use other HTTP methods. A <form> tag will usually have a method attribute on it with one of the methods in it, like this form that is going to POST data to the comment.php file:
<form method="POST" action="/comment.php"><!-- ... --></form>
The browser is going to turn that into an HTTP request that starts with this Request-Line:
POST /comment.php HTTP/2
Search engines will only use the GET method. If you have URLs on your site that can only be viewed with other kinds of requests, search engines won’t find them. This will become clearer once we wire up some forms from scratch.
The GET Method Transmits Data in the URL
When forms use the GET method, the form fields get put into the URL as parameters.
You can see an example of that when you go to google.com and perform a search. As soon as you submit the form, the URL will change the one that has URL parameters in it.
The parameters will be found after a question mark in the URL.
In this example:
https://www.google.com/search?q=green+widgets&num=100
the search parameters are this part of the URL:
?q=green+widgets&num=100
which tell Google to search for “green widgets” and show 100 results:
q = green+widgets
num = 100
Google Disaster Story
Links are followed with GET requests, so if you have a link on a page that isn’t blocked to bots, the bots are going to fetch it and cause the backend to perform its action for that URL.
Many years ago there was a company that used GET requests on the links that were used to delete items from their database.
So Google found the links and followed them using GET requests. Every time Google crawled one of those links it deleted that customer data.
The solution to that problem is to convert the delete links into buttons and make sure that the buttons perform an HTTP verb that bots won’t follow. In modern Web development, that HTTP verb would be DELETE. Search engine bots will follow links but they typically won’t push buttons or use HTTP methods other than GET.
Takeaways
Things that you should remember from this section:
- HTTP requests have methods or actions attached. (
GET,POST,PUT,PATCH,DELETE) - The HTTP method is specified by the Web client (e.g., browser) in the first line of the request.
- Search engines will only make
GETrequests. - URLs that modify data should not be accessible with
GETrequests, or search engines might accidentally modify website data while doingGETrequests.