1
00:00:00,351 --> 00:00:04,560
Narrator: Our next verb is the POST verb.

2
00:00:04,560 --> 00:00:08,160
Now, the POST verb is used to add resource.

3
00:00:08,160 --> 00:00:13,160
If you remember, you used GET to get, or retrieve a resource

4
00:00:13,890 --> 00:00:18,120
and the POST verb is used to add resource.

5
00:00:18,120 --> 00:00:20,700
The POST verb should contain a message body

6
00:00:20,700 --> 00:00:23,970
that specifies the resource to be added.

7
00:00:23,970 --> 00:00:25,530
Or in other words,

8
00:00:25,530 --> 00:00:29,580
when sending a request using the POST verb, then

9
00:00:29,580 --> 00:00:34,580
sending a verb and a URL like in the GET verb is not enough.

10
00:00:34,950 --> 00:00:37,230
The request should contain a body,

11
00:00:37,230 --> 00:00:40,546
so that the server will know what resource it should add.

12
00:00:40,546 --> 00:00:43,335
And this information, naturally, is not contained

13
00:00:43,335 --> 00:00:46,920
in the URL itself because the URL points

14
00:00:46,920 --> 00:00:49,710
to the resource address to be added

15
00:00:49,710 --> 00:00:51,780
and not to the resource itself.

16
00:00:51,780 --> 00:00:55,590
So again, a request using the POST verb should always

17
00:00:55,590 --> 00:00:59,340
contain a body, specifies the resource to be added.

18
00:00:59,340 --> 00:01:00,990
Now another thing to note

19
00:01:00,990 --> 00:01:04,019
about the POST is that a POST request should not

20
00:01:04,019 --> 00:01:07,110
contain any query string parameters.

21
00:01:07,110 --> 00:01:08,760
If you remember, with GET

22
00:01:08,760 --> 00:01:13,170
we can use query string parameters, but with POST we cannot.

23
00:01:13,170 --> 00:01:18,170
So a URL like that is not valid for POST verb.

24
00:01:18,660 --> 00:01:19,530
Okay, great.

25
00:01:19,530 --> 00:01:22,473
So let's do a short demo of the POST.

26
00:01:23,460 --> 00:01:27,660
So like in the previous demo, we will begin with Beeceptor.

27
00:01:27,660 --> 00:01:30,351
And again let's click the Mocking Rules

28
00:01:30,351 --> 00:01:34,020
and we will create a new rule.

29
00:01:34,020 --> 00:01:38,760
And here, make sure to select POST in the Method.

30
00:01:38,760 --> 00:01:42,390
So the URL of the API, of the POST API, we are going

31
00:01:42,390 --> 00:01:46,380
to create will be /API/order.

32
00:01:46,380 --> 00:01:51,380
And we will respond by saying that the status

33
00:01:51,540 --> 00:01:55,803
of adding a new resource is created.

34
00:01:56,760 --> 00:01:58,770
Now later in this course we'll discuss what is

35
00:01:58,770 --> 00:02:02,070
the right way to return a created status.

36
00:02:02,070 --> 00:02:04,230
It has something to do with the status code.

37
00:02:04,230 --> 00:02:07,855
There is a specific status code Designate created

38
00:02:07,855 --> 00:02:10,830
but again, we will talk about it later.

39
00:02:10,830 --> 00:02:13,560
As of now, we will stay with the 200 status

40
00:02:13,560 --> 00:02:17,010
and the response body that contains the status created.

41
00:02:17,010 --> 00:02:18,000
Okay, great.

42
00:02:18,000 --> 00:02:22,005
So now let's save the rule and go to Postman

43
00:02:22,005 --> 00:02:24,330
to test the API we just created.

44
00:02:24,330 --> 00:02:27,510
And again, I will drag it from my other monitor.

45
00:02:27,510 --> 00:02:28,343
Here it is.

46
00:02:29,220 --> 00:02:30,270
Okay, great.

47
00:02:30,270 --> 00:02:33,450
So, in order to test the API we made, we are going to

48
00:02:33,450 --> 00:02:38,450
first select the POST verb from this dropdown.

49
00:02:38,490 --> 00:02:42,510
And now let's just enter, oh, it's right here.

50
00:02:42,510 --> 00:02:45,300
Let's just enter the URL of the API.

51
00:02:45,300 --> 00:02:48,007
Now, note something interesting.

52
00:02:48,007 --> 00:02:50,940
Do you remember the URL that we tested

53
00:02:50,940 --> 00:02:53,790
in the previous lecture with the GET verb?

54
00:02:53,790 --> 00:02:58,290
So note that the URL itself, this part, is identical.

55
00:02:58,290 --> 00:03:01,320
It has the same domain and the same ending.

56
00:03:01,320 --> 00:03:05,640
It's API/order, but from the REST API point of view

57
00:03:05,640 --> 00:03:07,980
it's a completely different API

58
00:03:07,980 --> 00:03:10,410
because the verb is a different one.

59
00:03:10,410 --> 00:03:13,890
So again, don't look always only on the URL,

60
00:03:13,890 --> 00:03:16,503
always look also on the verb.

61
00:03:17,637 --> 00:03:21,690
As we said earlier, in order to use the POST verb

62
00:03:21,690 --> 00:03:23,760
we need to include a body.

63
00:03:23,760 --> 00:03:28,440
So, click here on the Body tab and select row.

64
00:03:28,440 --> 00:03:30,701
With row we can type the exact string

65
00:03:30,701 --> 00:03:33,450
that will be sent to the server.

66
00:03:33,450 --> 00:03:34,901
So naturally in this case, we want the body to

67
00:03:34,901 --> 00:03:39,900
represent a new order that we want the server to add.

68
00:03:39,900 --> 00:03:44,190
Let's type in a JSON representing a new order.

69
00:03:44,190 --> 00:03:46,213
And we will do it like this.

70
00:03:46,213 --> 00:03:48,150
(keyboard clicking)
This is an order, and

71
00:03:49,500 --> 00:03:54,500
the order has an order date, which is this one.

72
00:03:59,130 --> 00:04:02,073
And an order user,

73
00:04:05,640 --> 00:04:08,370
which we will do it like this.

74
00:04:08,370 --> 00:04:10,750
And let's add also

75
00:04:14,940 --> 00:04:19,940
the total cost of the order and we will put it like this.

76
00:04:20,490 --> 00:04:21,390
Okay, great.

77
00:04:21,390 --> 00:04:22,650
And we'll close this.

78
00:04:22,650 --> 00:04:26,310
And so we have a JSON structure represent the

79
00:04:26,310 --> 00:04:28,652
new order that we want to add.

80
00:04:28,652 --> 00:04:32,313
So we built this body and let's click Send.

81
00:04:37,249 --> 00:04:40,650
And we've got exactly the status that we expected.

82
00:04:40,650 --> 00:04:42,360
So the status is created.

83
00:04:42,360 --> 00:04:44,460
Of course, we are getting here the 200

84
00:04:44,460 --> 00:04:47,373
which is exactly what we asked Beeceptor to return.

85
00:04:48,420 --> 00:04:52,770
Size is the same as the previous demo, 218 bytes.

86
00:04:52,770 --> 00:04:56,310
And it took a little bit more than one second.

87
00:04:56,310 --> 00:04:57,143
Okay, great.

88
00:04:57,143 --> 00:05:00,240
So this is how we are using the POST verb.

89
00:05:00,240 --> 00:05:04,020
So again, the POST is used to add a resource

90
00:05:04,020 --> 00:05:07,803
and in this demo we added a new order to the server.

