Skip to content

HTTP Request Methods#

In HTTP, you send requests that contain somethings called the "request method". Here's some of the most common request methods (verbs) you'll see throughout your career:

  • GET
  • HEAD
  • POST
  • DELETE
  • UPDATE

There are others too, but they can be discovered and read about later on.

These request methods (sometimes called verbs) are used to tell the remote web server what it is you want to do: fetch something, send something, delete something, etc.

I'm going to review two of the most common requests that you'll see when investigating HTTP issues. The other request methods are going to be part of your homework. First though, what's the format of a request?

Request Format#

Here's the example given by Wikipedia:

1
GET /images/logo.png HTTP/1.1

Here we can see the three components mentioned: "the case-sensitive request method, a space, the requested URL, another space, the protocol version":

1
request-method requested-url protocol-version

Simple enough. Other information called "headers" can be added to the request as well. We'll cover headers in a bit more detail later on, but essentially all they look like is:

1
2
Host: www.example.com
Accept-Language: en

So a key: value configuration. Very simple.

Combined we get this formation:

1
2
3
GET /images/logo.png HTTP/1.1
Host: www.example.com
Accept-Language: en

Which can see as a format structure of:

1
2
3
4
5
request-method url protocol-version
header-key: value
header-key: value
header-key: value
header-key: value

Let's look at what a GET is and then we'll look at some common HTTP header types.

GET#

This request method is used to get information from the remote web server, and have it transfer from the remote server to the local client. It's like going into a shop and asking for something off of the shelf: "Can you GET that for me, please?" and (a copy of) the item is given to you.

This the most common HTTP request method you'll see. Many, many GET requests are sent to a web server when you first request a website. Here's an example of the GETs sent to linkedin.com after I requested the website in my Firefox browser:

LinkedIn GET Requests

LinkedIn GET Requests

And that's a small amount of the requests that were sent. There are hundreds of them for the one website.

What you need to understand here is a GET is about *GET*ting information from the remote server - asking for some information, state, image, data, etc. to be sent to you, the client.

Note

The HEAD method is like a GET, sort of. Can you discover the difference?

POST#

Instead of requesting information from the remote web server, a POST sends it. This is like POSTing a written letter: you package up a bit of information and then you POST it to your recipient.

But what data would you send to a web server? How about uploading an image? What about when you fill in a form on a website to register for a service? These are all POSTed to the remote web server for processing. Let's look at an example of a POST being used to submit a form.

Check out this screenshot from the EMS Simple POST Form Demo. You can follow along, if you like, by visiting the website, loading the developer tools for your browser (Firefox, Chrome), and then filling in and submitting the form. Here's what my form looks like:

EMS POST Form Example

EMS POST Form Example

First, we can see the GET request my browser sent to the web server:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
GET /about/science-system-description/eosdis-components/esdis-metrics-system-ems/examples/post-form HTTP/1.1
Host: earthdata.nasa.gov
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://www.google.com/
DNT: 1
Connection: keep-alive
Cookie: f5_cspm=1234
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: cross-site
Sec-Fetch-User: ?1
Pragma: no-cache
Cache-Control: no-cache

That's a big request compared to what we've seen so far, but don't worry about it. All you're looking at is that HTTP request format we saw earlier: the request at the top followed by the HTTP headers. There are loads of HTTP headers you can send but don't worry about that for now.

All that's important in the above is the GET I'm sending and asking for the form:

1
GET /about/science-system-description/eosdis-components/esdis-metrics-system-ems/examples/post-form HTTP/1.1

The form is returned to my browser and then rendered so that we can interact with it.

After I click the "Submit" button my web browser reads the form and composes a POST request. It sends it to the remote web server. Here's what it looked like for me:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
POST /about/science-system-description/eosdis-components/esdis-metrics-system-ems/examples/post-form HTTP/1.1
Host: earthdata.nasa.gov
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 53
Origin: https://earthdata.nasa.gov
DNT: 1
Connection: keep-alive
Referer: https://earthdata.nasa.gov/about/science-system-description/eosdis-components/esdis-metrics-system-ems/examples/post-form
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Pragma: no-cache
Cache-Control: no-cache

Inside of the data that was sent I can see this:

1
name=Michael+Crilly&read=yes&explain=Books.&op=Submit

That's the information I put inside of the form: name, read, explain. These are the fields on the form which my web browser read and then packaged into the POST request and sent to the remote web server for processing.

I got a response from the server too:

EMS POST Form Response

EMS POST Form Response

And that's the basics of a GET and a POST. All this will become a lot clearer when we start building out a simple web server, writing some simple HTML, and fetching the information from the server ourselves using the curl command.

Now we need to talk about are HTTP status codes.