1
00:00:00,330 --> 00:00:07,530
All right, and up next, I want to finally discuss method versus batch method, so why in this API,

2
00:00:07,770 --> 00:00:12,870
in our out we use batch and during tutorial we used pot.

3
00:00:13,440 --> 00:00:14,180
So here's the deal.

4
00:00:14,520 --> 00:00:19,620
Yes, put and patch are both are both for updating the resource.

5
00:00:19,620 --> 00:00:26,190
But the assumption is that when you use put, you're trying to replace the existing resource.

6
00:00:26,640 --> 00:00:29,240
And patch is for partial update.

7
00:00:29,730 --> 00:00:36,030
And since I'm fully aware that this might sound like mumbo jumbo to you, let me give you an example.

8
00:00:36,660 --> 00:00:45,240
So if we go to our postman and more specifically, update desk, if the idea is correct.

9
00:00:46,180 --> 00:00:50,720
Then only the properties that I'll pass in will be updated.

10
00:00:51,130 --> 00:01:00,370
So in this case, if I'm going to go with shake and bake number two and I'll actually remove completed

11
00:01:00,820 --> 00:01:04,250
only the property that is passed, then will be updated.

12
00:01:04,420 --> 00:01:12,070
So if I send check it out now, I get the task and I can clearly see that completed is there, even

13
00:01:12,070 --> 00:01:13,040
though I didn't pass it.

14
00:01:13,480 --> 00:01:13,950
Why?

15
00:01:14,350 --> 00:01:18,230
Because that's how our functionality is set up in the controller.

16
00:01:18,820 --> 00:01:23,570
So if I'll pass completed and I'll set it equal to falls, of course it will be updated as well.

17
00:01:24,010 --> 00:01:27,550
So if I go here completed and I'll set it to false.

18
00:01:27,550 --> 00:01:28,020
Yes.

19
00:01:28,030 --> 00:01:33,440
In this case, since I'm passing the property, of course, now I'm going to get the new result.

20
00:01:34,000 --> 00:01:35,990
Now what is the difference with put.

21
00:01:36,340 --> 00:01:40,830
Well, let me go the long route and actually set up one more controller.

22
00:01:40,840 --> 00:01:44,290
But keep in mind that this is going to be just a temporary controller.

23
00:01:44,620 --> 00:01:50,330
So if you don't want, you can just sit back and relax and we'll start in our out.

24
00:01:50,650 --> 00:01:53,920
What essentially I want to go with my route.

25
00:01:54,190 --> 00:02:01,870
And in this case, I'm still looking for this forward and then call it because, again, the functionality

26
00:02:01,870 --> 00:02:03,280
is going to be almost the same.

27
00:02:03,670 --> 00:02:07,000
But I'm looking for a different method and I'm looking for pot.

28
00:02:07,270 --> 00:02:09,910
And of course, now we just need to create the controller.

29
00:02:10,220 --> 00:02:16,570
And eventually I'll call this update or I'm sorry, Eric, task, just search a little bit different.

30
00:02:16,840 --> 00:02:22,780
So, of course, I'm not exporting that yet, but I'll right away set it here in mind structure.

31
00:02:23,080 --> 00:02:27,400
I say add a task and then back in the controllers.

32
00:02:27,850 --> 00:02:30,790
I just want to go below the update desk again.

33
00:02:30,790 --> 00:02:36,640
This is just going to be temporary, but I'll go with const edit and the task and that one is going

34
00:02:36,640 --> 00:02:39,840
to be equal to whatever I have over here.

35
00:02:40,210 --> 00:02:46,070
We simply need to add one more option in the find one and update.

36
00:02:46,390 --> 00:02:51,850
So let me select this whole thing just so we don't have to type it from scratch and all the way in the

37
00:02:51,850 --> 00:02:54,730
bottom we're going to go with a task.

38
00:02:55,180 --> 00:02:58,000
And like I said, it's going to be temporary sern here.

39
00:02:58,000 --> 00:03:05,260
I'm not going to say it with all my roots, but let me just save my current ones and I'll close all

40
00:03:05,320 --> 00:03:07,660
these windows and let's set up a new route.

41
00:03:08,230 --> 00:03:10,600
So in this case, it's going to be a pot root.

42
00:03:11,170 --> 00:03:17,500
And remember, we have one variable, so I'm looking for URL and then I'm looking for tasks.

43
00:03:17,950 --> 00:03:20,200
And of course I want to grab some kind of vidi.

44
00:03:20,650 --> 00:03:24,340
So let me get again all the tasks here.

45
00:03:24,970 --> 00:03:29,670
And I'm going to stick with Shikimic because I like that name so much.

46
00:03:30,360 --> 00:03:38,320
Let me grab this out of here, then back in tasks will pass it in and let's try to recreate the same

47
00:03:38,320 --> 00:03:41,290
functionality that we have for now in the patch.

48
00:03:41,470 --> 00:03:46,960
Essentially, what I really want is just pass in some data in my body.

49
00:03:47,380 --> 00:03:52,930
So I'm going to go here with Raw Guy and we're looking for JSON and we'll set it up.

50
00:03:53,170 --> 00:03:58,270
Name equal to John, nothing particularly original.

51
00:03:58,630 --> 00:04:05,050
And once I say, of course, now, Shake and Bake has the name of John, but here comes the biggest

52
00:04:05,050 --> 00:04:10,930
difference between what method that we're using over here and the patch method.

53
00:04:11,290 --> 00:04:20,860
So idea with put is that if I send only the name, my expectation is that all the rest of the properties,

54
00:04:20,860 --> 00:04:25,690
which of course in our case is just completed, will be removed from that item.

55
00:04:25,690 --> 00:04:27,490
So we will replace that item.

56
00:04:27,850 --> 00:04:30,010
And how is that going to look like in our controller?

57
00:04:30,310 --> 00:04:33,610
Well, here everything is going to be exactly the same.

58
00:04:34,090 --> 00:04:36,880
But by default, Mongo's doesn't do that.

59
00:04:37,420 --> 00:04:42,970
By default, Monroes is going to be like, OK, so you want to get the item, you want to update it.

60
00:04:42,970 --> 00:04:43,450
Awesome.

61
00:04:43,750 --> 00:04:47,920
Just get me the properties you want to update and rest of them will stay the same.

62
00:04:48,460 --> 00:04:54,850
And if I actually want to remove those properties, the ones that I'm not passing in with my request,

63
00:04:54,850 --> 00:04:56,620
I need to add another option here.

64
00:04:57,220 --> 00:04:58,720
The option is all right.

65
00:04:59,410 --> 00:05:01,590
And we need to set it equal to true.

66
00:05:01,930 --> 00:05:09,940
So now you'll notice that back in my postman, if I sign here with name and let's just keep it interesting

67
00:05:09,940 --> 00:05:11,920
and pass in beta, check it out.

68
00:05:12,130 --> 00:05:15,210
We have a name and the computer is still there.

69
00:05:15,370 --> 00:05:16,420
Now it's still there.

70
00:05:16,720 --> 00:05:21,390
Well, because in our model we have default set default.

71
00:05:21,700 --> 00:05:23,320
So there is some default one.

72
00:05:23,590 --> 00:05:30,400
If I remove it, you'll notice that with our method, the way the controller works right now, if I

73
00:05:30,400 --> 00:05:37,180
send it right now, then of course I'll just get the name so complete it is not there anymore.

74
00:05:37,480 --> 00:05:44,190
So if I take a look at all the tasks now in the first one actually completed is missing.

75
00:05:44,590 --> 00:05:45,610
So that is.

76
00:05:45,610 --> 00:05:54,010
Going to be the difference where when we work with put the expectation is that will replace the item,

77
00:05:54,300 --> 00:06:01,150
so we'll just pass in the properties that we want to set up an item and then the rest of them effectively

78
00:06:01,150 --> 00:06:02,430
will be removed.

79
00:06:02,860 --> 00:06:08,110
But when we're working with Patch, we're just updating the properties that we're passing.

80
00:06:08,110 --> 00:06:15,040
And just remember that in real life you will see the APIs where they put method is used with the same

81
00:06:15,040 --> 00:06:17,150
functionality as the patch.

82
00:06:17,170 --> 00:06:22,690
Now, in our case, for the remainder of the project will use the patch one instead.

83
00:06:22,900 --> 00:06:29,590
So therefore our remove this added one and here as well and the same I want to do in or out.

84
00:06:29,800 --> 00:06:34,830
OK, I said this is just for demonstration purposes, so save it here.

85
00:06:35,050 --> 00:06:41,110
And I also want to remove this rod from my postman just so it's not in a way.

86
00:06:41,380 --> 00:06:42,430
So say don't save.

87
00:06:42,670 --> 00:06:44,920
And I'm back to my five roots.

88
00:06:45,130 --> 00:06:48,370
And of course for the update, I'm using the patch one.

