1
00:00:00,590 --> 00:00:09,950
Let's continue building our arrest API in this demo now when they use a lot of thing to our application

2
00:00:10,430 --> 00:00:15,480
we might want to list all the notes created by him or her.

3
00:00:15,860 --> 00:00:25,340
So we are going to create Getaround that runs a crazy operation on dynamo Levy and returns up to say

4
00:00:25,610 --> 00:00:33,390
five nodes created by the user and sorted by the time stamp in descending order.

5
00:00:35,030 --> 00:00:46,610
So router are get slash API slash notes we call it nodes in plural form since we are expecting to receive

6
00:00:47,090 --> 00:00:50,330
one or more items in response.

7
00:00:50,720 --> 00:00:53,840
And then the processing function

8
00:00:56,520 --> 00:01:07,250
lets declare the pad on some variable table name is table name and so we specify the key condition expression

9
00:01:07,340 --> 00:01:19,910
are the where clause of our query operation as user ID equals colon U R and D and then define colon

10
00:01:19,910 --> 00:01:24,590
you ID using the expression attribute values.

11
00:01:24,690 --> 00:01:35,860
So we are attempting to create all items with hash key equal to the user id of the logged in user limit

12
00:01:35,910 --> 00:01:37,080
as a limit.

13
00:01:37,150 --> 00:01:44,770
And I want to create or limit variable or declared a limit variable to take in an optional limit value

14
00:01:44,800 --> 00:01:47,710
from the string.

15
00:01:47,780 --> 00:01:58,040
So if that calling application pro-white a limit value we return that main number of items as we default

16
00:01:58,460 --> 00:02:00,420
to about 5 items.

17
00:02:01,830 --> 00:02:10,260
We also want the items to be in reverse chronological order meaning the recently created Nel's should

18
00:02:10,270 --> 00:02:12,090
appear first.

19
00:02:12,090 --> 00:02:23,120
So so are the items by times Dan or the sarky in descending order to do that which specifies scanning

20
00:02:23,130 --> 00:02:32,690
less forward as far as and this would return items sorted by the sarky in descending order.

21
00:02:35,200 --> 00:02:45,720
Then since this is passionated query we want to restart key we have the user id We just need to know

22
00:02:45,760 --> 00:02:52,990
the time stamp from the last evaluated key return in the previous operation.

23
00:02:53,110 --> 00:03:01,290
So our API Quest can send in an optional star barometer as crazy string.

24
00:03:01,600 --> 00:03:08,430
And we use it as the star key to get to the next page of items.

25
00:03:08,540 --> 00:03:16,860
So let's define a variable star times tab and get its value from request.

26
00:03:16,930 --> 00:03:26,980
Dart Querrey Darkstar we have to pass the query string paramita call start to get that next page for

27
00:03:26,980 --> 00:03:28,220
the first page.

28
00:03:28,240 --> 00:03:32,410
We don't need to parse this Parminter.

29
00:03:32,830 --> 00:03:38,240
And if it is not Basto we assume it to be zero.

30
00:03:41,000 --> 00:03:51,800
Then if the start time span is greater than zero we populate the exclusive Starky to query the next

31
00:03:51,800 --> 00:03:53,930
page of results.

32
00:03:59,720 --> 00:04:03,860
Finally we call the document blind method.

33
00:04:04,550 --> 00:04:06,380
Just like that

34
00:04:31,550 --> 00:04:39,600
and in the success call we turn the data along with our 200 success response.

35
00:04:43,310 --> 00:04:45,340
Let's test this out.

36
00:04:51,200 --> 00:04:57,320
First let's make the API call without any start parameter

37
00:05:12,970 --> 00:05:22,720
and we do get five items with the latest item at the top and then we also have the last few valuated

38
00:05:22,720 --> 00:05:24,440
key here.

39
00:05:31,600 --> 00:05:41,290
Let's copy the time stamp from here and we'll pass it to the same request as a star parameter in the

40
00:05:41,290 --> 00:05:43,270
query string.

41
00:05:43,330 --> 00:05:49,230
So question mark Starr equal to the time stamp that be copied.

42
00:05:56,930 --> 00:06:00,820
Hit send and receive them.

43
00:06:00,820 --> 00:06:03,890
Next page of results.

44
00:06:03,950 --> 00:06:05,200
Awesome.

45
00:06:05,930 --> 00:06:15,290
So now our application can show the names created by the user and user can navigate through them page

46
00:06:15,290 --> 00:06:16,750
by page.

47
00:06:16,820 --> 00:06:26,170
Next if the user clicks on a node from this list he or she should be able to read the complete node.

48
00:06:26,220 --> 00:06:33,510
So for that let's create another API out to return the selected note.

49
00:06:33,710 --> 00:06:37,100
So we'll use the get method again.

50
00:06:37,340 --> 00:06:43,640
This time we want the user to parse the node ID of the node to be returned.

51
00:06:44,150 --> 00:06:55,370
And this should be mandatory parameter so we specify the mandatory pattern meters inside the API endpoint

52
00:06:55,490 --> 00:07:06,410
Lysa router door get slash API slash node slash colon node ID here.

53
00:07:06,560 --> 00:07:15,500
Note ID is the mandatory parameter that user must send in in order to make this API car.

54
00:07:15,620 --> 00:07:26,570
And then the processing function as usual we get the node Id passed by the user from request dog pass

55
00:07:26,630 --> 00:07:30,580
of it just like that.

56
00:07:30,720 --> 00:07:35,790
Then lets move the parents argument for our Querrey operation.

57
00:07:35,790 --> 00:07:42,380
This time we only have the note ID and we dont have the time stamp.

58
00:07:42,780 --> 00:07:51,950
So we'll create the global secondary index that we have created on the node ID to give.

59
00:07:52,460 --> 00:08:03,210
So Table name is table name index name as node ID index and we can find the actual indexed name from

60
00:08:03,210 --> 00:08:10,760
the indexes tab in the Dynamo the console right here.

61
00:08:11,690 --> 00:08:21,000
All right then we specify the red Glaus using the key condition expression lights.

62
00:08:21,330 --> 00:08:34,310
Note ID equal to call an ID and then we define the colon ID is an expression attribute values like so.

63
00:08:39,020 --> 00:08:51,770
We can also specify a limit as 1 since we don't expect to have two items with the same node ID then

64
00:08:51,770 --> 00:08:55,020
we call the document client operation.

65
00:08:55,160 --> 00:08:55,990
As usual

66
00:09:27,040 --> 00:09:35,330
and if that ease success response there is a possibility of an empty response as well.

67
00:09:35,930 --> 00:09:41,550
We just check if the state handout items is empty or not.

68
00:09:52,630 --> 00:10:09,810
If it has data out we return the first item from the Arey Lysa else we turn 4 0 for not found response.

69
00:10:09,820 --> 00:10:11,410
All right let's test the

70
00:10:15,060 --> 00:10:20,090
let's speak up a note Id from our dining table.

71
00:10:25,080 --> 00:10:26,810
And made the API call

72
00:10:43,400 --> 00:10:46,760
just like that.

73
00:10:46,940 --> 00:10:50,580
And we do get the requested item.

74
00:10:50,600 --> 00:10:52,330
Awesome.

75
00:10:53,480 --> 00:11:02,970
Now I'm going to duplicate an item inside dynamo D.B and change the user id times that A.I

76
00:11:14,610 --> 00:11:16,110
just like that.

77
00:11:17,520 --> 00:11:26,230
Let's assume that this item was inserted by another user called Test User 2.

78
00:11:26,340 --> 00:11:36,510
And now if we make a get request with this no tidy Ideally they should see an error because the item

79
00:11:36,510 --> 00:11:39,110
belongs to another user.

80
00:11:39,780 --> 00:11:41,030
Let's try that out.

81
00:11:48,340 --> 00:11:48,790
Oops.

82
00:11:48,830 --> 00:11:53,180
But the API returned the item from another user as well.

83
00:11:54,320 --> 00:12:01,850
And we'll fix this issue using fine grained access control when we implement Federated access using

84
00:12:01,990 --> 00:12:04,440
in the US go to meet her.

85
00:12:04,610 --> 00:12:09,460
Next up we want the users to be able to delete the display node.

86
00:12:09,740 --> 00:12:21,140
For that we're going to use the delete method router dot delete slash API slash no slash Kurland time

87
00:12:21,140 --> 00:12:23,930
stamp to delete an item.

88
00:12:23,930 --> 00:12:28,020
We must pass they complete primary key.

89
00:12:28,160 --> 00:12:30,630
We already have the user id with us.

90
00:12:30,650 --> 00:12:36,080
So we simply asked the user to provide us with the time stamp.

91
00:12:37,070 --> 00:12:47,340
And it should be a mandatory parameter and then the processing function we capture the time stamp from

92
00:12:47,440 --> 00:12:50,180
request Dar Patten's object

93
00:12:58,620 --> 00:13:08,570
pass it inside the parents variable as a key attribute along with the user id just like that.

94
00:13:08,960 --> 00:13:13,610
And then we called the document blind darg delete method

95
00:13:22,660 --> 00:13:24,420
just like that.

96
00:13:57,860 --> 00:14:00,060
Let's test this out.

97
00:14:05,890 --> 00:14:14,410
Simply big time stamp from Dynamo the table and make a delete request with that time stamp.

98
00:14:29,950 --> 00:14:31,770
Just like that.

99
00:14:32,170 --> 00:14:34,990
And we get 200 OK response.

100
00:14:35,290 --> 00:14:43,220
And if we refresh the data in the table in the code and so we do see that the item has been deleted

101
00:14:50,380 --> 00:15:02,250
ASA our API is now ready and we are now ready to integrate things that are front end to build and end

102
00:15:02,250 --> 00:15:06,740
to end web application.

103
00:15:06,750 --> 00:15:12,300
This has been a long lecture and thank you so much for bearing with me.

104
00:15:12,300 --> 00:15:15,780
If you need to take a break do take one.

105
00:15:15,810 --> 00:15:23,160
And when you come back we'll integrate this rest API with the front end application.
