Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
HTTP: Do You GET It?
Links
Familiarize Yourself
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
First off, thanks for coming out on such a
nice sunny day to learn about HTTP.
0:04
This is very, very impressive.
0:09
So like they've said, I'm the Java
teacher.
0:12
And I'm starting to get into the web side
of Java.
0:14
We've, we've got kind of the basics of it
started.
0:17
And we started to dive in and I realized.
0:18
Thinking about what I needed to teach for
the web, the web side of things.
0:21
You could just jump right into a framework
or
0:25
you could, could kind of like, look around
a little bit.
0:26
But it's kind of best, I think, to know
what's going on.
0:29
What, how is this working?
0:32
How is all this stuff kind of working?
0:33
So, what I, what I did is I kind of, I
kind of planned a small little.
0:34
A little workshop here, for us to walk
through.
0:40
And I realize that my development
adventures, I kept on being,
0:43
like, oh, I never knew that.
0:46
Oh, that's cool, that's really cool.
0:48
And doing this, this workshop, I also
found a couple more cool things out,
0:49
that I hope, you, as well, have aha
moments.
0:52
So this is going to be my first time using
this application that does stuff like.
0:56
This.
1:01
So, that might make you a little sick
because I've never done that.
1:02
And I'm also not very good at design,
1:05
as you'll see, as you'll notice as these
slides grow.
1:06
So that also might make you sick, those in
the house that are, are front-endy.
1:09
On that last set of things.
1:13
So, so, what is this thing?
1:15
What is this, this Hypertext Transfer
Protocol?
1:16
So, a protocol is a set of formal rules
describing how to transmit or
1:20
exchange data, especially across a
network.
1:24
And we have all sort of protocols like
this.
1:26
So for like, for instance, if I was to be
some, do something like.
1:27
When I say tree, you say house.
1:30
Tree.
>> House.
1:33
>> You see?
1:34
We got a protocol going.
1:35
Like, just like that.
1:36
I made a request.
1:36
You guys did a response.
1:37
Just like that.
It's that easy.
1:38
It's not that much different, actually, if
we look under here.
1:40
There's a couple more little rules in
there.
1:43
But so let's, let's dive in a little bit
more.
1:45
So, http Hypertext.
1:47
I should have, look, I can go backwards.
1:52
Watch.
1:54
So, Hypertext is a, the concept of
documents that are linked together.
1:55
And, that, that word is kind of from the
'90s.
2:01
And, it kind of has that '90s feel, right,
like hypercolor, hypertext.
2:04
It's got that, that vibe.
2:07
Okay, so but basically it's what we know
of the internet and what we
2:09
really know like the early internet which
we'll, we'll look at here in a bit.
2:12
But it's, it's document that can link to
other documents basically, right?
2:15
And, and the concept that we're trying to,
that this was trying to do,
2:20
like how, how do we do that?
2:22
How do we send that information back and
forth?
2:24
So, so, let's take a look at this.
2:26
So, there's a client.
2:27
And the client sends a request to the
server.
2:29
Okay?
2:32
So, then the server sends a response back
to the client.
2:33
And that's it.
2:36
Okay?
2:37
So, the client is like a web browser or a
phone or, actually,
2:37
there's anything, really.
2:41
You could actually open up a little window
on your computer and
2:42
send a request to a web server.
2:45
And there's actually a program that
everybody has on,
2:48
on their computers, and we can put a link
to it.
2:51
It's called Curl, and
2:55
let's take a look really quick at what
some of those results look like.
2:56
So, so here you look, I, I was on my Mac
and I typed curl dash v.
3:00
And I went to the Team Treehouse site and
the stars there are kind of basically,
3:05
they're like comments so it fixed my url
and it said it wasn't found in the cache
3:09
and it connected and, then, that first
line in there is actually the command,
3:15
the protocol that was sent so the, the
first bit here.
3:19
I don't know.
3:22
Is my mouse showing up?
3:23
Yeah.
3:24
The first bit here, the get.
3:25
This is the method that it's in and this
is the path.
3:27
So, I said get this, the forward slash to
the root of the, the thing.
3:31
And then it, then the what, what version
of the protocol?
3:35
And, you'll notice that this has been
around since the '90s and
3:37
we're only at one point one, currently.
3:40
There has not been much movement on it.
3:43
And, you'll see why.
3:45
It's actually pretty, it's a pretty simple
protocol.
3:45
So over on the left side of these so, so
it sent that command enter.
3:48
These are keys and on the right is the
value.
3:54
So it's a key, colon and then the value.
3:58
So user agent is basically who is making
this request and in this case it's curl.
4:00
I'll show you in a bit what happens when a
cul,
4:05
when a, when an actual browser sends,
sends that.
4:07
And then the host of what's going on, who
we are asking for, and
4:10
then accept, and star dot star, so that's,
that sends the request and that says, hey.
4:16
Hey server, give me, I want to get that
data.
4:21
Okay?
So now, we've got server, so
4:25
we had servers sitting in here, so.
4:27
Most likely there's an Apache server
sitting there,
4:30
there could be all sorts of different
server frameworks sitting there.
4:31
That server is responsible to say, oh, I
know what you're talking about.
4:36
Here let me give that to you.
4:40
And so that looks like this,
4:41
and this is off from the same part of the
curl request.
4:43
And you'll notice that the arrows are
going the other way.
4:47
So this is going back to the client.
4:49
This is, this is the response and he says
okay so this is http one dot one, 200.
4:50
That's a status code.
4:56
We'll look at those in a bit.
4:57
And he says okay, cool you got, you got
this.
4:58
So server is not blacklisted.
5:00
And then it sends back it's set of header
values.
5:02
So header fields.
5:04
So server and this is the server that
we're running.
5:06
There's lots of different key values in
here which we'll,
5:10
we'll go through as we go.
5:14
Sometimes you can send the content link of
how much you can expect to get back.
5:17
And also again it will send the status,
5:21
all these Xs here in the headers, they're
experimental.
5:25
But some of them are so experimental and
the, like I said,
5:29
the spec's been around for a very long
time, and the x means experimental, but
5:32
a lot of people are using them as like,
this is like the standard.
5:36
You can kind of rely on these being here.
5:38
This is how cookies get set.
5:43
I'm sure everybody has, has worked with
cookies before or
5:44
kind of understand the basic concept of
cookies.
5:48
We'll, we'll dive a little bit deeper.
5:50
>> In a bit on that but so
5:53
the response is saying hey client I want
to set this cookie on you.
5:54
And again we're looking at the team
treehouse site so
5:59
basically what we're doing is we're just
kinda starting up a session here.
6:02
I am not logged in, this is just some
generic session that came across.
6:06
And then, and then it ends and then you'll
see here that payload.
6:09
You'll see the whole, all the rest of the,
the documents coming across.
6:12
So this document just came down this is
just text here.
6:16
There's gonna be other links like our
JavaScript files and our CSS files and
6:18
our images file.
6:21
And it's the clients responsibility to
then go ask for all of those.
6:23
But basically, this is we're done.
6:27
Right, so.
6:28
I made the request.
6:30
And the response came back and we're done.
6:32
It's basically this.
6:33
The transaction's over.
6:35
That's all of the, all of the protocol
talking that happens.
6:36
If we start up again, it does, has no idea
who I was.
6:39
And, and that's a concept called being
stateless.
6:42
So this really,
6:47
is really simple if you picture it like we
did way back in the 90s.
6:48
Right?
Cuz this was happening in the 90s when
6:53
websites.
6:54
We're just kind of like, coming out.
6:56
And this is, this is 90's.
6:57
And look at this.
6:58
This is, this is the flagship Apple site.
6:59
They're introducing a thing called cyber
drive.
7:02
So again you know, cyber, cyber.
7:05
You can register today for a free cd-rom.
7:08
This is on their home page.
7:11
And also you'll notice that everybody
7:12
is getting the BMW ad directly on their
homepage.
7:14
We've got some.
7:17
You know, some stuff here that probably,
nowadays, would make somebody cringe.
7:18
But this is Apple, this is the main site.
7:22
This is, this is like, just a random, a
select list, there.
7:23
Here's, maybe this might be a dropdown.
7:28
I'm not sure what this is.
7:30
The standards aren't around yet.
7:30
But just to kind of get your mind in this
set, that,
7:32
like, this is, this is what it kinda
looked like back then.
7:35
Maybe this is even a frame.
7:37
And, and let's look at a couple more of
those actually.
7:39
So, this is, this is Yahoo, so very well
laid out and
7:42
you could go through and you know, click,
click these, these hypertext, right?
7:47
Send this stuff.
7:52
And send this document over.
7:52
Here's a beautiful one.
7:55
This is the MSN page.
7:55
You could get 180 in M-S Cash.
7:57
And it's just kind of amazing, right, that
we, we built on top of this but
8:00
then just to think about where we went.
8:03
And the whole time its been sitting on
this protocol, this, this protocol.
8:05
And people have pushed this to different
limits, right so.
8:09
Part of the problem in, in this page is
probably, you know, you can have a custom
8:12
start page so that's cool so that's oh
you'll, you'll know who I am?
8:16
Like I'm that.
8:20
Let's get in that mindset of like whoa,
8:20
this ,the computer knows who I am I'm
gonna talk back and forth with this thing.
8:22
So it's stateless okay, so HTTP is
stateless, I can log, log in to my,
8:26
to this webpage and walk away and, come
back, and it doesn't know that I left.
8:33
It's a stateless, I send a request, and a
response, and a request, and a response,
8:38
and it doesn't remember who I am just by
sending these requests,
8:42
it's a It's a It forgets, it's just one
transaction.
8:45
But, that's not really how we work.
8:49
And that's not really how business has
worked, and
8:51
so we've needed to figure out some way to
do a shopping cart, right?
8:53
Because what good is something if you
can't buy.
8:57
Anything.
Right?
8:59
So, that's, that's where we started going
with this.
9:00
We're like, we gotta, we have to figure
out some way to put state into this.
9:02
So, we tried a couple different things and
9:06
some people will remember this sort of
trick.
9:08
It's still around a little bit.
9:11
So, this is a form.
9:14
An HTML form.
9:15
And you'll notice here, you'll start
seeing some.
9:16
Some of these, this method here is in HTTP
method, and this is about posting and
9:19
we'll, we'll touch on that here in a
second.
9:23
And there's actually this great website
called httbbin.org, and
9:25
it's for practicing things like this, what
this is actually going to do is when I
9:30
press the submit button it's going to
actually submit there and it will send,
9:33
show us back what it got, and what it
knows about.
9:37
So the trick, the, that was kind of picked
up.
9:40
Is this hidden bit, so you can sit a
little hidden field in there, so
9:43
you could say like oh, this is, this is
Bob he's coming, and every time Bob
9:46
would submit a form, we'd have a little
hidden field that says this is Bob, and
9:50
the server on the other side would be like
oh, it's Bob, okay so
9:54
I'm going to draw this page a little bit
differently just for Bob.
9:57
But that was kind of how we started doing
and so you click submit.
10:01
And this is, this is the results from htt
bin and
10:07
you'll see that these here's, whoa.
10:09
[LAUGH] You'll see, sorry about that.
10:11
You'll see, here's some request headers
that were sent.
10:15
And this was sent from, I did this today
from my, from my web browser.
10:18
So let's go, let's get that back out a
little bit.
10:23
This is the user agent that was sent.
10:26
I'm using Chrome.
10:28
And so I don't know if this key, if you
can see what that says.
10:29
It says us, user agent in this very long
string including Mozilla, that's my Mac.
10:32
There's some software that you can use to,
to determine who, what that is, but
10:37
that's, what, what is sent, sent forward.
10:40
We said that my request was 40 characters.
10:43
I put in my, my first name and it was able
to know what it was.
10:45
So, we said here's the form, Craig, and
there's the section, one, two,
10:49
three, four, five.
10:51
But it did that very similarly.
10:52
It's a post to is, to slash post and then
it pushed that data through.
10:54
So, same sort of request though, it said
post, and then the key value.
10:59
The request and then the response got that
information and sent it back.
11:03
We can play with that in a little bit.
11:08
So another idea was cookies.
11:12
Right?
So, and when cookies came on the scene,
11:15
everybody was, like, uh-uh.
11:17
Not in my backyard.
11:18
You are not following my data around,
there's no way you guys are going to be
11:20
storing this, this information and it's
very creepy, and like the news got
11:23
involved and it was like tonight at ten,
danger, cookies on your computer.
11:26
Everybody was so afraid of these things,
and
11:30
basically what it was, what we were saying
was like no we want,
11:34
we want to be able to track and know who
you are, we don't want this session to go.
11:37
So, there's, there's different types of
cookies and there was,
11:42
there used to be like this like big, you
know, go, go turn on your cookies and
11:45
you can, you can check and you say that
you only want web session and
11:50
then when you, when you close your browser
there'll be,
11:52
that that cookie will go away or, or you
can say I'll allow people first party, but
11:54
I don't want to allow third party people
on, to do that.
11:58
Now, the trick about cookies is, we saw in
the HTTP request, those are sent
12:02
using the same, the same protocol, their
HTTP protocol.
12:08
So, wherever it goes, it brings back that
cookie.
12:12
So you can, you can go up, and you can
send the cookie back.
12:15
So, if the cookie's on your machine.
12:17
Little piece of data on your machine, and
you go to another page and
12:19
that same third party's there, it will
send it back up, okay?
12:22
So because the request every time you make
a request for an image it sends those
12:27
cookies back, so the cookies are sent in
that HTTP request for that specific thing,
12:32
so that's kind of what everybody was
upset, was upset about was that,
12:36
oh now these ads are, you know, I'm over
here and I saw some shoes.
12:40
And now I'm over here and I see some
shoes.
12:43
How will you guys know that I'm interested
in these shoes?
12:44
And that's how they're doing it.
12:47
They're using, they're, they're pushing
these cookies across because every HTTP
12:48
request sends the cookie.
12:52
Right?
So, you ask for the image.
12:54
The image of the pair of shoes.
12:56
And, when you send that request, you send
up the fact that you have the cookie and
12:58
that you've look at those shoes before.
13:01
So, or where you're coming from.
13:03
So, so that's kind of why people were so
freaked out about cookies.
13:04
But then, the web sort of did something
kind of weird.
13:08
It did this.
13:10
There were errors like this, where it
said, you, you can't use our site.
13:12
Nice try.
13:15
No, we need to have your cookies.
13:17
And for some reason, we were like, oh,
cool.
13:18
And its interesting right, like its a, I
don't know how that worked,
13:21
but its like I can't, I guess if I can't
use Facebook, I'm not going to.
13:26
So that, that sort of problem is now
present everywhere.
13:30
So every time you go and
13:34
get an image, they have the ability to
store some cookies on your machine,
13:35
unless you go in and try to figure out
where those cookie settings are at.
13:38
So, but, that's not very popular any more.
13:42
To like, even worry about that sort of
thing.
13:44
So, let's take a look at some of these
header fields.
13:49
This, this presentation has a, some hard
links in here.
13:54
So, these are the fields that you can put
on the request.
13:59
And again, these kinda help the server
understand what you're looking for.
14:02
So, one of the things, you know,
14:07
if you ever end up on a site that's like
an Italian site.
14:09
And you can say that I accept the
language, in your request.
14:12
And normally, your, your, your browser's
gonna do that for you.
14:16
It's gonna say that I, I speak English.
14:19
And that's a setting that you can put in
your computer.
14:21
So I, I speak English so when you go to it
that's how it says
14:23
oh you speak English would you like us to
translate this in English?
14:25
Or you go to it and it goes and drops you
in the right place.
14:28
That sort of thing.
14:30
So that's, that's a header that the
request can send.
14:32
The client sets on it, right?
14:35
And here's the cookie, the cookie header
so again it's like,
14:37
every request that goes it sends your
cookies up for whatever that domain is.
14:40
There's lots of good caching stuff on
here, so this is from the Wikipedia
14:45
document that's a very thorough list of
everything that's in here.
14:51
And they talk it's pretty well-written and
14:56
maintained, I recommend looking at it,
there's links in there.
15:00
So user agent again.
15:05
This is, this is so, you know, you could
tell if they were coming from mobile.
15:06
You could see somebody's IP address, and
so, in a little bit here what we'll
15:11
look at is we'll look at how server-side
frameworks kind of expose this in a way
15:16
that you might have already seen if you've
worked in some server-side frameworks.
15:21
And then, we'll also look at some
client-side frameworks that are kind of
15:24
doing some of this work for you.
15:26
But know that the way that all of this is
working is through this.
15:29
All the magic of, of how the cool tricks
that you see on the web,
15:32
it's coming from this.
15:37
So I think it's, its important to kind of,
understand, and also to innovate.
15:38
Right, like, if we think about what that
Apple sight was doing, there was so
15:43
much innovation that happened after that,
and it was all kind of on top of this.
15:48
Okay, so it was all on top of this, this,
oh, we have this information,
15:51
this key value store that we can send back
and fourth to each other.
15:55
So this also goes into some of the
nonstandard request fields,
16:00
but they're starting to be more, more
requested and
16:07
again they start with the x and then here
are the response fields.
16:10
Okay.
So, the server comes up.
16:17
The server, and the server can fill back
and, and tell you different things.
16:18
So, one of the things that I wanted to
touch on is this content disposition.
16:21
So you could actually send somebody a PDF
by setting this header or you send
16:26
somebody some sort of file that you want
them to download that you generate.
16:30
That's kind of how that trick works, when
you click it it says download this
16:33
type of file the content length,
16:36
a lot of this stuff is used by the client
to know how much data to expect and
16:41
there are also ways of making sure that
you stream, it's kind of a more,
16:47
newer version of it where it says hey, I'm
gonna send you chunks of data.
16:53
And this, you can do that through these
headers here.
16:57
And again, all of those tricks are usually
wrapped up in
17:02
in abstraction from the framework.
17:06
So this will kind of back and forth, and
one of the, one of the things that
17:11
you will see, and these will start looking
very familiar, maybe you didn't realize
17:15
that they were actually coming from HTTP,
but they're status codes.
17:19
And you normally probably don't see these,
these one 100 versions here but
17:23
they're kind of grouped by the hundred.
17:28
So, the, the first thing's informational
and next is success, so
17:31
you, you would see 200, okay, that's the,
the good deal there.
17:36
This is also, also a Wikipedia document
here.
17:39
So 300 are redirects.
17:43
Okay?
So what,
17:45
what can happen is you request a page.
17:47
And the page is moved.
17:50
And so you send a thing to the client.
17:51
And the client goes and gets a new.
17:53
A new thing.
Normally this is done, through a framework
17:54
these days, but you can actually just say
hey, this page has moved, it's over here.
17:58
And you can say it's moved permanently, or
it's found, or see other, and
18:03
this is a newer one.
18:07
So like, this you should also see this,
also check this out.
18:09
>> So these are probably, this one
especially, this 404 not found, so
18:14
the 400 is when there's an error on your
side, 400, you've asked for
18:18
something wrong, 401, you're not allowed
in and you haven't tried to log in yet.
18:21
But when you do log in and you come back,
you hit this 403 forbidden.
18:28
So it's you're logged in, I know you are,
but you're not allowed to see this, and
18:32
that's an error code that you'll get back.
18:36
Sometimes unfortunately, actually I want
to show you this one.
18:37
This is an April Fool's joke that lived
forever.
18:43
If you look at 418 I'm a little teapot.
18:46
Should probably make that a little bit
bigger.
18:48
Sorry about that.
18:50
Just saw that on the screen.
18:51
So it says, I'm a teapot.
18:53
And it's an actual April Fool's joke.
18:55
It's really great.
18:56
You should, you should come in here.
18:57
It defines the Hypertext Coffeepot Control
Protocol.
18:59
So it's an error because it tells a teapot
to brew coffee.
19:02
And it can't brew coffee, cuz it's a
teapot.
19:05
It's usually used in testing HTTP
libraries.
19:08
But it's pretty funny.
19:11
Check out.
19:12
And, then, of course, the dreaded 500
internal server error, which, I think,
19:14
all of us who have developed a server-side
framework have seen that and
19:20
generated those and watched their page say
500, no!
19:25
These are, these are all great to look at.
19:31
And what, what's nice is usually the
reason why you, this internal server error
19:32
looks good is this is usually what gets
returned as well.
19:37
So you'll see the 500 and then this short
little description here of what that is.
19:39
That's might be why those look familiar.
19:42
So, this is htt bit, http bin that I was
talking about that you could play with.
19:45
It's really nice.
19:51
You can, you can test out, a little
framework and hit this thing and
19:52
see what comes back.
19:55
See what you're sending and what comes
back.
19:56
It, it's really informative, I think in
learning what this,
19:58
what this stuff is doing.
20:01
Let's talk a little bit about those
request methods.
20:03
So when we first saw that first example of
curl, I used GET.
20:07
And then when I used the form, I used
POST.
20:11
And those are the two that you can do
from, from, from the browser just,
20:13
just starting from a form post, or GET and
POST.
20:17
But, there's more.
20:21
So, so GET is a, is a concept of, I want
this information, and
20:25
when you give me this information, don't
make it change anything else.
20:28
Don't, don't have any sort of side effect.
20:31
I should be able to call this GET as many
times as I want and nothing will change.
20:33
And that's kind of the, the concept of it.
20:36
And if you, if, nothing forces you to do
that on the server side of things.
20:39
If you're writing a server-side program,
you could be like, oh,
20:43
you called this page with a GET, I'm gonna
go update some database record.
20:46
But you, you don't wanna expose that, for
the reason that if something came across
20:50
crawling your website and hit that, it
could automatically, you know,
20:55
insert thousands of records into your
database or cause some sort of thing.
20:59
And so it's a unspoken agreement that any
time you call GET,
21:03
you're not expecting it to change
anything.
21:08
Now, when you do wanna change something,
that's when you use POST.
21:12
So you're posting data, you're posting a
chunk of data to
21:14
this URL, and it's making a change.
21:19
That chunk of data might be should delete.
21:24
Well, actually, there's a delete thing
here, but should update or
21:26
change the name or whatever.
21:30
These HTTP verbs start looking familiar
for those of you who are using REST.
21:32
So REST is a concept that sits on top of
these, and it helps provide state.
21:40
And we'll take a look a little bit here at
just a very little bit,
21:47
cuz I would like to do a separate talk on,
on REST specifically.
21:52
But it uses these verbs that already exist
to actually mean something.
21:57
So PUT is an update.
22:04
If it doesn't exist, it will update and
override.
22:07
So, you have to provide the whole set of
the information.
22:10
So I might, you say, I'm gonna put data at
this, and if the thing doesn't exist,
22:14
it will create it or it will update the
thing that is existent there.
22:18
And PATCH means it's a partial update,
and, it's, not,
22:21
it's not fully supported and most
frameworks have written around
22:25
the fact of, if you try to call PATCH on
something, it will fix that.
22:29
We're not gonna talk too much more about
REST.
22:35
I kinda see a little bit of of glaze over
on the REST.
22:36
So we will not, not be doing that too
much.
22:40
I did wanna show you one other cool little
trick.
22:44
There is there's this Live HTTP Headers.
22:46
And what this does is it, it sits here in
my Chrome, and
22:50
it watches everything that happens, every
HTTP request that happens, it shows.
22:54
So I'm gonna go ahead and I'm gonna open
up our friend Facebook, no,
23:00
I'm gonna open up my Twitter.
23:04
Let's flip back here to this Live HTTP
Headers, and
23:06
this is the number of HTTP requests that
have gone out since I started.
23:08
And I'm gonna open up one of these.
23:12
You can't see my whole thing, but
23:15
this is really nice, cuz it shows you the
request that was made.
23:17
So there's my GET to that certain
notifications sync since the last sync,
23:20
trying to make sure that my, probably my
number pops there.
23:25
So it's sending that AJAX request
continuously, polling.
23:27
And it's continually going, and let's see.
23:33
So it's been on, I don't know, like, how
long was that, like, a minute?
23:35
And I've done, like, 400 HTTP requests.
23:38
So it's pretty crazy, and it's kind of
interesting to go and look through this,
23:40
cuz you can also see, let's see, where are
they at?
23:44
So many here that.
23:50
We'll see the ads.
There will be an ad show up here shortly,
23:52
I'm sure.
23:56
Actually not sure what this is.
24:00
But maybe that, maybe that was an ad that
came across.
24:03
But anyway, so basically, we're sending,
and I'm sending cookies out.
24:04
And all of these, all of these images that
I went,
24:08
and this is kind of how they know where
I'm going.
24:10
Wait.
24:13
Though that, thought that's kind of
interesting.
24:15
A really interesting way to kind of
explore how this is working.
24:16
All right.
Let's get back to.
24:21
Okay.
24:22
So.
24:26
I'm talking about these things being
abstracted.
24:27
And this is where if you, if any of that
stuff was kind of new,
24:32
feeling new, this'll start feeling
comfortable, I think.
24:37
This'll start feeling like things that
you've seen.
24:42
So I'm gonna walk through a couple of
abstractions that's
24:44
sitting on top of this HTTP.
24:46
So first we'll start on the server side,
right?
24:50
So this is the side that's responsible for
creating the response.
24:52
So let's take a look and see how Node,
Node works.
24:57
Node is pretty clear on exactly what it's
doing.
24:59
So there's a, a library called http, and
it gets back a request.
25:02
That's your HTTP request.
25:07
And a response, and that's the HTTP
response.
25:09
And this is the status code, 200, which we
saw was okay.
25:11
And these are the key values of the
headers that it's passing across.
25:15
Okay, so and then it's saying end, and it
says hello world, and
25:18
then it also starts up the server.
25:21
So that's Node, pretty clear, not too
abstracted.
25:24
This is Flask, so this is Python here.
25:28
What this is saying is, it's saying it
will accept a POST or a GET.
25:32
And this request object is available in
the global scope if you, you import it.
25:37
And it has the .method, which we were
just, you know, we talked about,
25:45
that was the first thing that it wrote
there.
25:48
So it says if it's a POST, then.
25:50
So if it's a post, if you're submitting
data to me, then go ahead and
25:54
try to see if it's a valid login, and if
so, log the user in.
25:57
Otherwise, say it's an invalid user name.
26:01
And then if it's not a post, so this could
either be POST or GET,
26:03
it's gonna go ahead and render the login
template.
26:06
Okay, kind of make sense?
26:10
So that's, it's got all the words that
we're sort of talking about there.
26:12
This all has the the request.form, so that
was the form that we typed in, right.
26:15
So if you type in the username and
password in that form,
26:19
that's what it's talking about, that's
what came across.
26:21
So here's Rails.
26:25
Rails is talking about how to do a
redirect.
26:27
And in the documentation here,
26:29
you'll see that it's an HTTP request
that's gonna set that 302 header.
26:31
It's going to say the URL that it's
supposed to go to,
26:36
again by setting a header.
26:39
And it's gonna send it down to the client,
and the client's gonna get it and go and
26:40
open up that page.
26:43
But again, this redirect is the concept of
HTTP that [UNKNOWN].
26:45
And here's Spring.
26:51
This is Java.
26:53
And, you will see that it is using the GET
and
26:54
the POST to handle the same, this is the
same page that's coming through here.
27:00
So it says, for all GETs do this.
27:04
Go ahead and say greeting and render the
greeting template.
27:05
And then for this one, it's saying, if
somebody posts a greeting.
27:09
If you've, if you're sending a data to
greeting, then let's go ahead and
27:12
handle the data specifically.
27:14
So there's two different methods, again,
sitting on top of this request method,
27:15
depending on how it's coming in.
27:20
So it's very common on the server side to
kind of,
27:22
to talk about these sort of things in, in,
on the HTTP level.
27:26
And it's simpler than it ever seemed, you
know.
27:30
Like, I remember looking at this stuff and
being like,
27:33
I don't understand how that works.
27:36
But it's really just this key value going
back and forth.
27:37
All right, so let's take a look on the
client side.
27:40
Everybody's friend here.
27:44
So this is jQuery, and jQuery has an ajax
call.
27:46
It also has a $.get and a $.post.
27:50
You pass it the URL, and there's the
method that it's writing out there.
27:53
There's the data that it gets pushed
across.
27:57
And the dataType was actually part of what
you could request.
27:59
You could say, you know, I accept HTML, I
accept JSON, that sort of stuff.
28:02
That is translated into the proper key in
the HTTP request.
28:08
So then, again, it makes that request and
sends it.
28:12
And then it catches it, and the textStatus
is what we saw on the other side,
28:15
200 OK, or I guess in this case, it's
catching it in a failure message, so
28:20
it would say something like, I'm a teapot
if, if we,
28:24
we posted to the I'm a teapot and got that
error back.
28:27
Okay, so this is a way higher level of
abstraction.
28:34
And this is from Ember.
28:38
This is a library that kind off has taken
it all away from you.
28:42
You don't really see what's going on.
28:45
But under the covers, this is actually
what it's doing, and
28:47
it, it is going to go ahead and make a new
POST.
28:49
It's unfortunate, this is called post,
this is a blog post.
28:53
So, keep that in mind.
28:56
So, it's just a variable named, let's just
say blog post.
28:57
And it's created that variable, and it
says blogpost.save.
29:01
Now, that knows, that object itself knows
that it's new, so
29:04
it's going to go ahead and it's going to
POST.
29:08
It's gonna do a POST to /posts.
29:11
And it figures that out just from the name
of, of it.
29:13
It's this, this magic, you follow the
convention and it just kind of works.
29:16
So when you call save,
29:21
it's gonna automatically do a POST that
saves that data.
29:22
And here the store.find, this will say, if
it's not locally here,
29:26
it will actually go and get a GET to
/posts/1.
29:30
Then this is, this is the magic of REST
that it's sitting on top of.
29:34
And then it's gonna do a post.save.
29:38
Now, because it already existed, it's
gonna do a PUT.
29:40
And it's gonna automatically know that
it's supposed to do the PUT for you.
29:44
So it's still using the same rules that
are set up, but it's been abstracted away.
29:47
And I think as we get further and
29:52
further along with this, we start seeing
websites being built faster and
29:56
thought about quicker because there's
this, like, convention happening.
30:00
So that's, that's kind of what's really
nice going on right now with REST.
30:02
Here it is in Angular.
30:07
It looks quite a bit like, like the Node
actually.
30:09
So, it has a HTTP dependency injection.
30:13
And it calls a GET, and it has, it will
come back and it will have the status,
30:18
that's the HTTP status, it will have the
headers, those are the HTTP headers but
30:23
in a, a JSON object, and the config of
what was sent.
30:28
And then similarly, it has a POST.
30:31
So you call post on it and you can send
the POST out.
30:33
So it's been all abstracted, but it's
still sitting there, right,
30:36
and it's still just doing the same thing
under the covers.
30:40
So when, just, I just want you all to keep
thinking about that,
30:43
think that all that is doing is making
that HTTP request and response.
30:46
[BLANK_AUDIO]
30:50
And I guess that is where we're at.
30:54
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up