WEBVTT

0
00:00.580 --> 00:07.060
I want to drive this point home 🏠 because it really, really is important, and that is we need to understand

1
00:07.060 --> 00:10.920
the difference between a GET request and a POST request.

2
00:11.170 --> 00:12.590
So let's take a step back.

3
00:12.610 --> 00:15.790
We've seen it when a user submits a form with a GET request,

4
00:16.860 --> 00:20.130
the data is appended to the URL, like this.

5
00:23.180 --> 00:28.220
Pretty straightforward. I mean, this example could happen, for example, when we send our username

6
00:28.220 --> 00:35.330
and password to a server for authentication. And oftentimes you may see developers use a GET request

7
00:35.330 --> 00:36.650
in order to do this.

8
00:37.250 --> 00:40.400
The problem and flaw with this is pretty obvious, though.

9
00:40.730 --> 00:49.190
Our credentials become exposed instantly in the URL itself, including your password, which here is "secret1"

10
00:49.190 --> 00:50.030
by the way.

11
00:50.690 --> 00:54.710
And one way around this flaw is to use the POST request.

12
00:55.050 --> 01:02.210
But there's also one other very, very big limitation on a GET request, and that is, that query string

13
01:02.210 --> 01:02.990
in the URL...

14
01:03.170 --> 01:04.850
that size is limited.

15
01:05.660 --> 01:12.080
I can't exactly remember what the size is now on the top of my head, but just realize it's limited and...

16
01:12.080 --> 01:16.350
this means we can only send a certain amount of information with a GET request.

17
01:16.880 --> 01:19.730
Why limit ourselves when we don't have to?

18
01:21.260 --> 01:27.690
So that's another reason why we use a POST request, because with POST, you can send significantly

19
01:27.690 --> 01:31.820
larger chunks of data to the server compared to the traditional GET request.

20
01:32.230 --> 01:34.630
But these benefits are only the tip of the iceberg 🏔️.

21
01:34.650 --> 01:40.150
In fact, why don't I just on the next slide, discuss the main benefits of a POST request.

22
01:40.920 --> 01:41.950
Yeah, I like that idea 😊.

23
01:41.970 --> 01:45.410
So let's do that now. With a POST request...

24
01:45.420 --> 01:50.340
I like to think of 5 major advantages versus a GET.

25
01:50.580 --> 01:51.240
What are they?

26
01:51.780 --> 01:52.920
Pretty, pretty straightforward.

27
01:52.920 --> 01:59.490
Firstly, parameters are not saved in browser history, which is very useful, especially for sensitive

28
01:59.490 --> 01:59.940
data.

29
02:00.550 --> 02:01.320
Secondly,

30
02:02.430 --> 02:10.470
you can't bookmark a POST request. Thirdly, and we already discussed this one, there is no restriction on the form data length...

31
02:10.470 --> 02:12.010
that can be submitted to a server.

32
02:12.720 --> 02:19.560
Remember, with a GET request you're limited in size that can be inserted in the URL. And you can probably

33
02:19.560 --> 02:21.530
already guess what the fourth one is going to be.

34
02:21.550 --> 02:26.390
It's similar to one and two, but users can't cache the POST data.

35
02:26.850 --> 02:32.420
And the other major benefit is that the data is in the body of the request, not in the URL.

36
02:32.430 --> 02:37.950
And this just makes a lot of sense, even for nothing else than just semantically. It makes sense that it

37
02:37.950 --> 02:39.780
should be in the body of an HTTP request. 

38
02:39.960 --> 02:42.000
These are pretty awesome advantages,

39
02:42.000 --> 02:42.260
right? 

40
02:42.870 --> 02:45.300
But on the other hand, we have a GET request.

41
02:46.050 --> 02:49.140
Those parameters can be archived in browser history.

42
02:49.140 --> 02:50.120
They can be bookmarked.

43
02:50.130 --> 02:51.150
It's easier to hack.

44
02:51.480 --> 02:56.290
It has restrictions on the form data length, and it can be cached by a user.

45
02:56.790 --> 03:04.080
I bet you can already start to feel intuitively that a POST request is much better in most, if not

46
03:04.080 --> 03:04.950
all instances.

47
03:05.220 --> 03:13.650
But we did discuss something very briefly in the previous lecture, and that is what about other method...

48
03:13.650 --> 03:17.160
types, like PUT, DELETE, UPDATE etc etc.

49
03:17.580 --> 03:19.770
We've already seen that in a form element,

50
03:20.280 --> 03:24.810
we are restricted on only using a GET or POST method.

51
03:24.960 --> 03:30.150
Well, truthfully, we can also use that dialog, which we briefly mentioned, but GET and POST are the most...

52
03:30.150 --> 03:34.560
common. So we can get around this by using an AJAX call.

53
03:34.710 --> 03:36.620
We can use whatever methods we want.

54
03:36.930 --> 03:37.650
So there we go.

55
03:37.650 --> 03:43.800
That's just a very brief summary on some of the differences between GET and POST. Throughout this course...

56
03:43.800 --> 03:48.090
we're going to be discussing these things in more detail as we go on and in different examples.

57
03:48.550 --> 03:52.110
So don't worry if you're not fully understanding it yet, by the end of this course, you're going to

58
03:52.110 --> 03:54.800
be a true, true expert in this.

59
03:54.990 --> 03:56.430
I'm so excited to continue.

60
03:56.430 --> 03:57.780
I'll see you in the next lecture.