I want to drive this point home 🏠 because it really, really is important, and that is we need to understand
the difference between a GET request and a POST request.
So let's take a step back.
We've seen it when a user submits a form with a GET request,
the data is appended to the URL, like this.
Pretty straightforward. I mean, this example could happen, for example, when we send our username
and password to a server for authentication. And oftentimes you may see developers use a GET request
in order to do this.
The problem and flaw with this is pretty obvious, though.
Our credentials become exposed instantly in the URL itself, including your password, which here is "secret1"
by the way.
And one way around this flaw is to use the POST request.
But there's also one other very, very big limitation on a GET request, and that is, that query string
in the URL...
that size is limited.
I can't exactly remember what the size is now on the top of my head, but just realize it's limited and...
this means we can only send a certain amount of information with a GET request.
Why limit ourselves when we don't have to?
So that's another reason why we use a POST request, because with POST, you can send significantly
larger chunks of data to the server compared to the traditional GET request.
But these benefits are only the tip of the iceberg 🏔️.
In fact, why don't I just on the next slide, discuss the main benefits of a POST request.
Yeah, I like that idea 😊.
So let's do that now. With a POST request...
I like to think of 5 major advantages versus a GET.
What are they?
Pretty, pretty straightforward.
Firstly, parameters are not saved in browser history, which is very useful, especially for sensitive
data.
Secondly,
you can't bookmark a POST request. Thirdly, and we already discussed this one, there is no restriction on the form data length...
that can be submitted to a server.
Remember, with a GET request you're limited in size that can be inserted in the URL. And you can probably
already guess what the fourth one is going to be.
It's similar to one and two, but users can't cache the POST data.
And the other major benefit is that the data is in the body of the request, not in the URL.
And this just makes a lot of sense, even for nothing else than just semantically. It makes sense that it
should be in the body of an HTTP request.
These are pretty awesome advantages,
right?
But on the other hand, we have a GET request.
Those parameters can be archived in browser history.
They can be bookmarked.
It's easier to hack.
It has restrictions on the form data length, and it can be cached by a user.
I bet you can already start to feel intuitively that a POST request is much better in most, if not
all instances.
But we did discuss something very briefly in the previous lecture, and that is what about other method...
types, like PUT, DELETE, UPDATE etc etc.
We've already seen that in a form element,
we are restricted on only using a GET or POST method.
Well, truthfully, we can also use that dialog, which we briefly mentioned, but GET and POST are the most...
common. So we can get around this by using an AJAX call.
We can use whatever methods we want.
So there we go.
That's just a very brief summary on some of the differences between GET and POST. Throughout this course...
we're going to be discussing these things in more detail as we go on and in different examples.
So don't worry if you're not fully understanding it yet, by the end of this course, you're going to
be a true, true expert in this.
I'm so excited to continue.
I'll see you in the next lecture.