Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
HTML anchors form the links by which we can navigate throughout the internet. In this video you'll see how the browser uses HTML anchor elements to form HTTP GET requests when a visitor clicks on the anchor.
The "Referer" Header
In an HTTP request, your browser includes a "referer" header, which is the page where the current request is initiated from. Looking closely, you might notice that "referer" is misspelled! The correct spelling is referrer, but the initial specifications included the incorrect spelling of the header. Because of its widespread use, the spelling has not been corrected.
-
0:01
When you hear the terms World Wide Web or
-
0:03
Internet, you might think of something that's highly connected.
-
0:06
As a spiderweb or fishing net needs to be in order to be effective.
-
0:11
Online, the web of the Internet is spun by what are called hyperlinks.
-
0:15
Today we've shortened that to simply links.
-
0:17
And we have a technical term for that in the browser.
-
0:20
They're called anchors.
-
0:22
We reviewed how anchors are created in HTML, so
-
0:25
let's now look at how they're related to HTTP requests.
-
0:30
Okay, I'm back in Chrome and I'm gonna navigate to httpbin.org.
-
0:36
On this page you see a long list of blue anchors and
-
0:38
clicking on each will take you to the linked page.
-
0:41
Remember, that destination is determined by the URL listed
-
0:44
in the href attribute of the anchor.
-
0:47
To show you more about Chrome Developer tools let's right click the html anchor
-
0:51
and choose Inspect Element.
-
0:52
So I'll scroll down to that /html resource and I'll right-click and choose Inspect.
-
1:00
What we see here is the original html that the browser used to produce, or
-
1:04
render, this anchor.
-
1:06
Notice it has an href attribute with the value /html.
-
1:11
This href value is the URL that the browser
-
1:14
uses to make a request to the destination.
-
1:17
Now you might think, this looks like a URI, Chris, not a URL.
-
1:21
Well, I'd agree with you that it looks that way.
-
1:24
But this is what's called a relative URL,
-
1:27
which means the URL listed is relative to the current URL.
-
1:31
If we look up top at our browser's address bar right here,
-
1:36
we see httpbin.org as the current URL.
-
1:39
So this /html down here is relative to that httpbin.org URL.
-
1:47
And the full URL would translate to
-
1:51
http://httpbin.org/html.
-
1:56
It's worth noting that modern browsers will hide the protocol from the address
-
2:01
bar if it's plain http.
-
2:03
Notice in Chrome I do not see http:// here.
-
2:09
So what happens when we click on the anchor?
-
2:11
Well, only one way to find out.
-
2:14
After clicking on it, the browser navigates to that page.
-
2:17
And what you see if you click on the Network tab is that by
-
2:22
clicking on the anchor your browser made an http GET request.
-
2:27
If I expand this I see the request method was a GET request
-
2:33
using the URL from the href attribute of the anchor, /html.
-
2:38
Let's put this all together.
-
2:40
When viewing the page http://httpbin.org
-
2:45
you saw a link on the page that said /html.
-
2:48
This link was created with an html anchor tag where the href
-
2:53
attribute's value is /html.
-
2:55
Remember that's a relative URL and the text displayed is also /html.
-
3:02
Upon clicking on that link the browser used the relative
-
3:04
URL from the href attribute and combined it with the URL
-
3:08
of the current page to construct a full URL of the destination.
-
3:12
This full URL is known as an absolute URL.
-
3:15
With the absolute URLs,
-
3:17
your browser has everything it needs to construct the http request.
-
3:21
Your browser makes a network connection to httpbin.org using port 80,
-
3:27
kinda like we did in Telnet, then sends a GET request for
-
3:31
the /html resource using HTTP/1.1.
-
3:35
It adds a bunch of headers according to the kind of content that are acceptable,
-
3:39
the type of device making the request, Chrome in our case,
-
3:42
the page that we're currently on, and among others, the language we prefer.
-
3:47
English in this case, though this is determined by your browser settings.
-
3:51
And that's what happens every time you click a standard HTML anchor in a browser.
-
3:56
That was a fancy illustration of something that's quite simple.
-
3:59
Clicking on an HTML anchor in a browser results in an http GET request
-
4:04
to the resource located at the URL specified in the anchor's href attribute.
-
4:10
I should tell you that only GET requests are made with these anchors, and
-
4:13
not post requests.
-
4:14
We'll see later how post requests can be made with a browser.
You need to sign up for Treehouse in order to download course files.
Sign up