1
00:00:01,520 --> 00:00:02,830
Hi, and welcome back.

2
00:00:02,830 --> 00:00:05,350
In this video we are going to run our app

3
00:00:05,350 --> 00:00:07,650
and try it out with Postman.

4
00:00:07,650 --> 00:00:10,820
First thing to do is to open up a terminal

5
00:00:10,820 --> 00:00:15,360
and run your project, your app.py,

6
00:00:15,360 --> 00:00:17,360
so I'm gonna do just that.

7
00:00:17,360 --> 00:00:18,620
We'll just bring it up on terminal here

8
00:00:18,620 --> 00:00:20,210
in Visual Studio Code, but of course you can

9
00:00:20,210 --> 00:00:21,670
bring up a terminal anywhere you want.

10
00:00:21,670 --> 00:00:23,160
You can use a terminal that you've been using

11
00:00:23,160 --> 00:00:24,910
throughout the rest of the course.

12
00:00:24,910 --> 00:00:26,150
That's totally fine.

13
00:00:26,150 --> 00:00:28,360
And what I've got here is I've got my virtual environment

14
00:00:28,360 --> 00:00:30,670
activated, and in this case I've named

15
00:00:30,670 --> 00:00:34,690
my virtual environment section11-venv, and you know,

16
00:00:34,690 --> 00:00:37,460
normally you'd call your virtual environment just vn.

17
00:00:37,460 --> 00:00:39,870
That's the convention in Python.

18
00:00:39,870 --> 00:00:42,020
In this case I've called it section11-venv

19
00:00:42,020 --> 00:00:44,010
just for completeness.

20
00:00:44,010 --> 00:00:45,490
But when you're creating your own projects,

21
00:00:45,490 --> 00:00:47,350
it would normally have a shorter name.

22
00:00:47,350 --> 00:00:48,810
That's fine though.

23
00:00:48,810 --> 00:00:53,203
Doesn't really matter, and then we're gonna run app.py.

24
00:00:53,203 --> 00:00:55,673
Okay, so we're gonna run our .py here,

25
00:00:55,673 --> 00:01:00,673
and you may notice a couple of extra lines

26
00:01:00,690 --> 00:01:03,220
get printed out compared to earlier on in the course.

27
00:01:03,220 --> 00:01:05,789
It's just a flask changing a little bit.

28
00:01:05,789 --> 00:01:09,220
But it's not a problem, and then we're running here

29
00:01:09,220 --> 00:01:12,350
on 127.0.0.1:5000.

30
00:01:12,350 --> 00:01:15,010
So let's go ahead and jump into Postman

31
00:01:15,010 --> 00:01:18,977
that I've brought up here, and we have our Stores REST API

32
00:01:18,977 --> 00:01:21,810
collection in Postman.

33
00:01:21,810 --> 00:01:23,100
So the first thing we're gonna do is,

34
00:01:23,100 --> 00:01:25,394
we are going to register a new user.

35
00:01:25,394 --> 00:01:29,180
Just as a reminder here, we are setting in a username

36
00:01:29,180 --> 00:01:32,293
and a password, and we're gonna pass that in,

37
00:01:32,293 --> 00:01:35,858
and but of course we don't have our environment URLs defined

38
00:01:35,858 --> 00:01:37,380
so I'm just gonna...

39
00:01:38,292 --> 00:01:41,083
Add one environment here.

40
00:01:43,040 --> 00:01:45,025
I think I must have lost it

41
00:01:45,025 --> 00:01:46,760
when I was...

42
00:01:48,550 --> 00:01:50,580
Changing a few things around.

43
00:01:50,580 --> 00:01:53,200
So that's the URL now defined.

44
00:01:53,200 --> 00:01:55,187
We can go ahead and send this again.

45
00:01:55,187 --> 00:01:58,160
And of course...

46
00:01:59,490 --> 00:02:00,883
It has to be 5000.

47
00:02:02,920 --> 00:02:05,130
My bug, let's do that.

48
00:02:05,130 --> 00:02:06,642
There we have it.

49
00:02:06,642 --> 00:02:09,760
User created successfully down here as you can see.

50
00:02:09,760 --> 00:02:13,520
So now we can log in and remember Flask-JWT,

51
00:02:13,520 --> 00:02:15,678
which is what our app is still using,

52
00:02:15,678 --> 00:02:19,592
uses the slash off endpoint, so we can send this

53
00:02:19,592 --> 00:02:23,070
and we get invalid credentials because we have

54
00:02:23,070 --> 00:02:25,090
the wrong user defined here.

55
00:02:25,090 --> 00:02:27,270
Let me just, remind me, there we go.

56
00:02:27,270 --> 00:02:28,722
user3 does exist,

57
00:02:28,722 --> 00:02:33,000
and we get our access token, and we have a few tests in here

58
00:02:33,000 --> 00:02:37,030
that save the access token to environment,

59
00:02:37,030 --> 00:02:38,760
so we can go ahead and see that the access token

60
00:02:38,760 --> 00:02:41,900
is saved in the environment here to the right.

61
00:02:41,900 --> 00:02:44,830
So now we have the access token,

62
00:02:44,830 --> 00:02:48,236
so we can go ahead, and for example, create a new item,

63
00:02:48,236 --> 00:02:51,253
and this item is gonna have this price and this store_id.

64
00:02:52,150 --> 00:02:53,951
We can go ahead and create that.

65
00:02:53,951 --> 00:02:56,720
Notice how now we get more information back from our API

66
00:02:56,720 --> 00:02:59,787
because we've updated item Json method,

67
00:02:59,787 --> 00:03:04,787
and also we can go ahead and, I think it's get,

68
00:03:05,111 --> 00:03:08,740
get an item, which requires an access token.

69
00:03:08,740 --> 00:03:10,480
We can go ahead and send that

70
00:03:10,480 --> 00:03:12,070
and we get the item information back.

71
00:03:12,070 --> 00:03:14,080
So that means our access token is all valid,

72
00:03:14,080 --> 00:03:15,570
we logged in successfully,

73
00:03:15,570 --> 00:03:18,530
everything is working as it did before.

74
00:03:18,530 --> 00:03:20,620
Now we can go ahead and close all of these

75
00:03:20,620 --> 00:03:25,620
and create a new endpoint that is going to be URL/user/

76
00:03:26,879 --> 00:03:28,870
the user ID, which is three.

77
00:03:28,870 --> 00:03:30,870
We should be able to send this,

78
00:03:30,870 --> 00:03:33,134
and as you can see, it says user not found.

79
00:03:33,134 --> 00:03:34,932
Of course the user ID will be one.

80
00:03:34,932 --> 00:03:38,710
Sorry, it's user3, but the ID of the user is one.

81
00:03:38,710 --> 00:03:40,690
The username's user3.

82
00:03:40,690 --> 00:03:43,967
So there you have it, ID one, the username is Jose.

83
00:03:43,967 --> 00:03:46,360
As a user, I picked it before actually,

84
00:03:46,360 --> 00:03:49,233
so our new user, user3 is ID two.

85
00:03:50,140 --> 00:03:53,100
So we have now a way of

86
00:03:53,100 --> 00:03:56,108
looking at the users that exist in our database.

87
00:03:56,108 --> 00:03:58,683
That can be quite handy when we're testing things out,

88
00:03:58,683 --> 00:04:01,690
and also, we can change this to delete

89
00:04:01,690 --> 00:04:04,538
and then we can delete a user like that.

90
00:04:04,538 --> 00:04:05,703
Okay.

91
00:04:06,920 --> 00:04:09,470
If we go ahead and get an item again,

92
00:04:09,470 --> 00:04:13,340
we can see that now we get an invalid JWT

93
00:04:13,340 --> 00:04:15,380
because the user no longer exists.

94
00:04:15,380 --> 00:04:20,280
So Flask JWT in the background is using the correct identity

95
00:04:20,280 --> 00:04:22,470
and so on and because we deleted the user,

96
00:04:22,470 --> 00:04:24,650
it's not, no longer working.

97
00:04:24,650 --> 00:04:26,696
This is exactly what we would hope would happen,

98
00:04:26,696 --> 00:04:28,410
and so that's all good.

99
00:04:28,410 --> 00:04:29,780
We're gonna learn throughout this section

100
00:04:29,780 --> 00:04:33,740
of a different way of essentially logging users out

101
00:04:33,740 --> 00:04:36,148
or handling when this doesn't happen,

102
00:04:36,148 --> 00:04:38,590
and using Flax JWT extended,

103
00:04:38,590 --> 00:04:40,900
so keep your eyes out for that,

104
00:04:40,900 --> 00:04:41,740
but that's it.

105
00:04:41,740 --> 00:04:45,710
Now we have been able to retrieve and delete users.

106
00:04:45,710 --> 00:04:47,937
We are going to just save these endpoints,

107
00:04:47,937 --> 00:04:50,863
save that and we're gonna call it,

108
00:04:52,193 --> 00:04:57,160
get user, like that.

109
00:04:57,160 --> 00:04:59,240
We're gonna save it in here,

110
00:04:59,240 --> 00:05:01,830
and we're gonna save the deletes as well

111
00:05:01,830 --> 00:05:05,303
as a new endpoint.

112
00:05:06,800 --> 00:05:07,633
There we have it.

113
00:05:07,633 --> 00:05:10,340
So now we have get and delete user IDs there

114
00:05:10,340 --> 00:05:13,630
in our collection all saved, which is good.

115
00:05:13,630 --> 00:05:16,340
I'm going to share with you a very similar collection

116
00:05:16,340 --> 00:05:19,588
to this one, as soon as we jump into Flax JWT extended,

117
00:05:19,588 --> 00:05:23,010
and just so you have a collection that is up to date

118
00:05:23,010 --> 00:05:24,810
and works with the API.

119
00:05:24,810 --> 00:05:27,539
I will share with you of a Postman collection

120
00:05:27,539 --> 00:05:30,580
you can import directly into your Postman window

121
00:05:30,580 --> 00:05:31,833
and it'll all work fine.

122
00:05:32,760 --> 00:05:33,790
So that's it for this video.

123
00:05:33,790 --> 00:05:35,433
Just wanted to show you how this works,

124
00:05:35,433 --> 00:05:37,113
and I'll see you on the next one.

