Welcome back.
In this video I want to talk a little bit more about HTP requests and how they work and what they look
like
sort of.
So remember when I go to a u r l and my browser like this one here it doesn't matter what it is.
And I hit enter the most important thing that happens there's a few steps but the most important step
is that HTP request is sent to a particular server's IP address and then the server figures out what
to send me and then it sends a HTP response back to me.
So if there's one thing you take away from all of this stuff about how the Internet works and HTP it's
the request response cycle you asked for a web page and you get one back to help us learn a little bit
more about requests.
We're going to use a tool called postman.
It's a free tool and the Web site is get postman dot com and all we need to do is click on get it now
and then it will take us to a Chrome extension page and then all you need to do is click this button
to install it.
And then once you have it installed you can launch the app.
So this is postman here.
I'll go ahead and make it full screen.
The whole point of Postman is that it lets us make HTP requests and viewer responses and it's really
for developers to understand how things are working possibly to debug something.
If the data is not coming back the exact way that you're expecting it to.
We're going to use that really as an educational tool and also use it for some debugging later on.
Once we start building some more complicated apps.
So before I actually demonstrated just want to remind you when I go to a web page and I click enter
I can doing here that it's making an HTP request but that's not the only way to make a request with
postman.
We don't actually have a web page and I can still make HTP requests.
I just want to reiterate that we can make requests from all different places.
We can make them from a browser like Chrome.
We can make them from an app like Postman.
We can make them from our command line from the terminal.
We can make them from other apps.
We can make them from the backend or from an iOS app.
So the idea of HTP requests are independent of browsers.
Let's go ahead and make our first request.
So when we make a request the most important part is the URL that we're making the request to which
is Google dot com in this case we're just trying to replicate.
When I go to Google dot com in my browser and I hit enter and then there's this choice here get post
patch put delete all these different what we call each TTP.
And these refer to different types of requests that we can make.
We'll be seeing these a lot more and spending more time in particular with get Post put patch and delete
.
These are the ones are much much less important.
I'll give you a very quick version of what they do.
These just tell the server what we're doing with the request.
What type of requests we're making if we're just retrieving information like retrieving the Google home
page.
That's a get request.
If I am signing up for a web site or creating a new comment on Facebook or submitting a new reddit post
or uploading those could be post requests where I'm posting new information to a database somewhere
I'm sending some data along with my request versus a get request.
Typically we're not sending much data along.
We're asking for data to come back and then put in patch are used to update things or to edit them.
So if I wanted to update the title of a Facebook image that I had uploaded after I had already posted
it I could use a put a patch request.
And of course the user doesn't decide on this ever.
This is what the developer decides on and then we have a delete request which does what it sounds like
when a server gets a delete request it expects that you're going to delete something.
But what's most important is that this is all just a protocol.
Remember that HTP stands for hypertext transfer protocol so it doesn't mean that just by sending a delete
request something is automatically deleted.
What it does mean is that it's a protocol.
So if I say that this is a delete request we should expect that it will delete something.
So again very high level overview will be going into depth with all of these here.
These first five verbs and the different types of requests.
When we actually make a server that handles them.
But to start I'm just going to make a get request to Google dot com and that's all we need to do.
And if I clicked send I get a few things back.
There are three important parts of every response the first one is the body of the response.
That's like the payload.
That's what is being sent back.
So the HD mal the C Ss and the javascript in this case.
And this is the H.M.S. s and Javascript of the Google homepage.
This is what we would see if we went to Google and did view page source just like this there we go.
So our browser just takes that and makes it look nice.
Then the other thing that we get back is the headers.
So the headers are like the meta data about the response so they contain a few pieces of information
.
The important ones that I'll point out are the content type.
So this says OK just to warn you I'm sitting back HMO because we can actually send back other types
which we'll see later on.
All that we've seen so far though is HMO.
Also the date and the time when this response happened when it was sent back.
And then this thing called status which we also get up here.
So the status code is a third big piece of information and it's just a number.
You've probably seen them before.
Most importantly 404 if you've ever seen before or for ever a status code.
It's just part of the protocol of HTP.
It's a standardized way of saying that the request that you made is good I'm going to send back status
code 200 because I found the page you're looking for.
Who'd you go.
But then if we sent a request to a page that doesn't exist the server need to wait to respond back to
us.
So there are different status codes and they each mean different things.
We'll be working with them again later on in the class.
So we have the body which is the content that's being sent back the headers which contain meta data
about the response.
And one of those pieces is the status code and that's just a number that represents the status of this
whole request slash response cycle.
So demonstrate this with another Web site like Reddit dot com just like that and we'll also make you
get request every time I load up my browser and I go to a you or I'll like Reddit dot com.
That is a get request.
I cannot make a post request from my browser search bar.
We can make a post request using a h l form which we mentioned briefly when we talked about forms and
we will be doing that.
For now we're just focusing on get requests.
Earlier I mentioned when we send a request like a get request we're usually asking for information back
and when we send a post request we're trying to add date data to a database.
So there's some sort of payload in the request where I'm sending in the information they want to be
added.
For instance the information to make and you post on Facebook or on Reddit.
But we still can send some data with a get request.
I'll give you a quick example.
If I go to Reddit outcome which I have opened here and I do a search.
So let's say I want to search for Corgies and I hit enter.
Notice what happens up here.
So it's Reddit dot com slash search question mark.
Q equals Corgies.
What type of requests do you think I make when I hit enter right here.
Well I just told you a few minutes ago that the only type of request we can make is a get request from
the browser's search bar or the nav bar.
So this is a get request but we're also sending a little piece of information along with it which is
our search term and it's still a get request.
We're not adding Corgies to a database anywhere.
We're not posting anything new to this application or to the database.
We're purely retrieving information retrieving posts that have Corgies in their title.
This is how we can send some data along with a get request.
It's called the query string.
So I can add in parameters here as many as I want something like name equals cold and it won't do anything
but the server will get that and if it was expecting a name if read it was expecting a name parameter
it would see that name is equal to Colt.
So I can tag as many of these as I want.
I can do another one here.
City equals Assef and I can keep changing these together but they don't mean anything except for q which
is something that the Reddit server is expecting on the search page.
Reddit dot com slash search.
When we make a request it's expecting queue to be equal to the search term.
One last thing about the query string is that it always starts after a question mark and that we separate
the key value pairs so q equals a corgi name equals cold.
They're separated by an ampersand to actually send one of these.
You can go back here and I can click on programs here and what harams let me do is I can add in your
parameter key and value.
So here let's say that I want Q To be equal to cats you can see postman makes this little request for
me and adds the query string in.
So now if I hit send here making a get request to read it dot com Q equals cats.
I'm not going to get back the search results because this is on Reddit dot com slash search not just
read it dot com.
So now if I go back and do Reddit dot com slash search Q equals cats.
This is making a request to the search page and saying we're searching for cats.
Let's quick send and go to body here.
We get a bunch of age Chimo and I'll scroll through and it's hard to see because there's so much information
but we have references to cats in the hd a male and a postman we can actually click on preview and we
can see that we get information about cats.
So these are all posts about cats.
It's not perfect.
The C Ss isn't showing up but it's at least the HCM mouth that we can view.
To summarize all of this we kind of covered a lot here.
First thing was that you can make a request from all sorts of different places.
It's not only in your browser.
Next thing is that every request has a verb or a type and we've been making get requests only so far
but soon we'll see post requests when we actually have a database going and we want to let users sign
up or submit a new comment or something like that.
They'll be sending a post request and our server is going to expect to post request and do something
when it gets supposed request.
So get requests are for retrieving information searching often just getting a home page or getting any
page that doesn't involve sending data but we can still send data with the Get request.
Usually it's when we're sending like a search query or another parameter about how we want the data
to be sorted or what order it should be in.
But the key is that we're still not adding anything to the database.
This doesn't change read it's database.
It's just asking for things that have cats in the title and all that logic happens on Reddit it's and
written in Python and Reddit spec and is going to see that we ask for Redditt dot com slash search as
a get request and then it has some code that will run when they get requests is made to read it dot
com slash search and in that code it will then look for the variable queue instead of the query string
.
Will take the corresponding value cats retrieve all the posts all the comments or whatever it does that
match cats and then send me back.
All this HD mail will be returning to postman later on in this course as a way of debugging some of
our own applications.
Next up we're going to start talking about node