1
00:00:05,440 --> 00:00:11,220
Hello everyone and welcome back in this section of the course we're going to talk about rest a prize.

2
00:00:11,290 --> 00:00:14,890
So our main goals for this section is to understand what rest is.

3
00:00:14,890 --> 00:00:18,480
Understand different use cases for rest especially as beginners and flask.

4
00:00:18,520 --> 00:00:21,460
It's often the case that you're not going to need rest right away.

5
00:00:21,640 --> 00:00:27,250
And then after we learn those use cases we're going to be able to implement a basic rest API flask web

6
00:00:27,280 --> 00:00:32,250
application that will implement basic authentication with flask and rest and that will also build the

7
00:00:32,260 --> 00:00:37,030
understanding of the flask restful library through a small simple example where we make direct rest

8
00:00:37,090 --> 00:00:42,940
API requests to a flask web application database and we'll also learn how to use the post man program

9
00:00:43,240 --> 00:00:50,180
in order to actually make these requests So let's talk about rest and the actual motivation of why we

10
00:00:50,180 --> 00:00:54,380
would even need it so far with only really visited our Web sites manually.

11
00:00:54,380 --> 00:00:58,730
That is to say with open the browser and view the actual template files that we were serving to the

12
00:00:58,730 --> 00:00:59,630
user.

13
00:00:59,630 --> 00:01:04,540
So literally that means we're only serving information visually through templates and views.

14
00:01:04,610 --> 00:01:08,370
But what if we just want to access to the correct information.

15
00:01:08,380 --> 00:01:14,060
What if we wanted a computer script or a server to the rectory access our database without needing to

16
00:01:14,060 --> 00:01:16,430
actually render things in the browser.

17
00:01:17,470 --> 00:01:23,430
Well for that we can use rest and rest stands for representational state transfer.

18
00:01:23,670 --> 00:01:29,730
And basically it allows us to provide interactions and operations between computer systems online.

19
00:01:29,830 --> 00:01:34,900
So the basic understanding is that rest is a standardized way for communication between computer systems

20
00:01:34,990 --> 00:01:40,750
on the web and systems that support and are compliant with rest are often known as restful.

21
00:01:40,750 --> 00:01:43,490
So if you have a web application you say it's restful.

22
00:01:43,570 --> 00:01:48,690
That means it's going to work with standardized rest requests.

23
00:01:48,700 --> 00:01:55,180
So let's talk about when to use rest because when to use rest and implement in your own projects is

24
00:01:55,180 --> 00:02:01,040
going to be really dependent on your final goal what you actually want your web application to achieve.

25
00:02:01,090 --> 00:02:05,230
And if you have no intention of automated systems communicating with your web site then you actually

26
00:02:05,230 --> 00:02:07,110
probably don't even need to implement rest.

27
00:02:07,120 --> 00:02:11,620
It's something that comes with more advanced creations of web applications.

28
00:02:11,740 --> 00:02:14,170
So let's go through a few use case examples.

29
00:02:14,200 --> 00:02:16,980
Let's imagine you're creating a Web site for an art gallery.

30
00:02:17,200 --> 00:02:21,790
Well in that case you have this nice web site and you're showing pictures of portraits or paintings

31
00:02:21,790 --> 00:02:22,210
that are up.

32
00:02:22,270 --> 00:02:24,780
Happened to be located in an art gallery.

33
00:02:24,850 --> 00:02:29,480
And for that sort of web site you might really only intend people to visit your site to see the pictures.

34
00:02:29,650 --> 00:02:32,460
So for that sort of use case probably isn't necessary.

35
00:02:32,740 --> 00:02:34,720
But again it always depends on the situation.

36
00:02:34,840 --> 00:02:39,340
But if your actual Web site the only intention is for people to manually visit the browser and then

37
00:02:39,490 --> 00:02:44,980
see the pages in the template and then view the pictures there the rest isn't going to be a very useful

38
00:02:45,040 --> 00:02:46,200
addition to your website.

39
00:02:47,610 --> 00:02:50,500
Let's imagine you built a web site for an online store.

40
00:02:50,550 --> 00:02:55,860
Now initially you may only intend people to manually shop online in which case you don't implement rest.

41
00:02:56,130 --> 00:03:00,840
But let's imagine your Web site for the online store begins to grow really popular and because it's

42
00:03:00,840 --> 00:03:06,310
growing so popular users want to create scripts to directly access items for sale programmatically.

43
00:03:06,330 --> 00:03:12,000
Maybe they want to actually visit your web site and then have programs automatically order shipping

44
00:03:12,750 --> 00:03:16,600
order items when they're running low internally.

45
00:03:16,670 --> 00:03:20,430
Now for that sort of thing the user eventually only has two options.

46
00:03:20,430 --> 00:03:25,050
Either they have to manually scrape your web site using some sort of their own programming scripts or

47
00:03:25,050 --> 00:03:32,190
own programming tools or you as the Web site creator can provide a rest API and API stands for application

48
00:03:32,190 --> 00:03:33,490
programming interface.

49
00:03:33,660 --> 00:03:39,270
Basically you can provide the tools for them to automatically or programmatically interface with your

50
00:03:39,330 --> 00:03:40,740
web application.

51
00:03:40,740 --> 00:03:44,450
So again really it's you providing an extra tool for the users.

52
00:03:46,520 --> 00:03:51,110
Now keep in mind there are many options available for implementing a rest API with flask.

53
00:03:51,110 --> 00:03:54,670
One of the easiest to use and most popular ones is the flask restful library.

54
00:03:54,680 --> 00:03:57,440
So that's what we're going to be using throughout the section of the course.

55
00:03:57,440 --> 00:04:02,930
So this library will be using to implement automated access to a flask web application and for the examples

56
00:04:02,990 --> 00:04:07,370
in this section of the course we're really just going to be focusing on the rest API portion of the

57
00:04:07,370 --> 00:04:07,960
Web site.

58
00:04:08,030 --> 00:04:11,960
You won't be worrying about creating templates or creating views since we don't really want to focus

59
00:04:11,960 --> 00:04:12,840
on that right now.

60
00:04:14,630 --> 00:04:20,390
So the general process for learning how to create rest API with flasks is to first learn about the postman

61
00:04:20,390 --> 00:04:21,250
testing tool.

62
00:04:21,440 --> 00:04:27,020
So we're going to download a little graphical interface that allows us to easily send then rest a get

63
00:04:27,080 --> 00:04:28,300
or post request.

64
00:04:28,520 --> 00:04:33,410
Then we're going to send the Jaison object back using rest and the flask restful library then we'll

65
00:04:33,410 --> 00:04:39,160
learn about the basic rest commands things like get Post put delete and then we'll implement authentication.

66
00:04:39,170 --> 00:04:42,650
That way people have to be authenticated before they can actually submit a rest.

67
00:04:42,650 --> 00:04:48,200
API request and then we'll implement finally a simple example of a restful flask web application and

68
00:04:48,200 --> 00:04:53,000
hopefully by the end of the section you'll be able to visit the examples on the flask flask restful

69
00:04:53,000 --> 00:04:57,560
Web site and be able to implement any of those examples the results are really useful ones there that

70
00:04:57,560 --> 00:05:00,460
I think will cover basically any use case that you're considering.

71
00:05:02,140 --> 00:05:07,300
So as far as the main things we're going to focus on with rest is just the main actions of creating

72
00:05:07,390 --> 00:05:12,100
reading updating and deleting and that should sound really familiar because we went over what is known

73
00:05:12,100 --> 00:05:12,810
as crud.

74
00:05:12,940 --> 00:05:14,680
We were talking about databases.

75
00:05:14,680 --> 00:05:21,760
So essentially we want to be able to programmatically perform crud type tasks with the API and the rest

76
00:05:22,000 --> 00:05:27,310
terms or the HTP verbs for this our post get put and delete.

77
00:05:27,310 --> 00:05:32,440
So basically if you want to create a new object in your database or on your Web site you can use post

78
00:05:32,440 --> 00:05:36,920
with rest if you want to get information about the object or read information you'd get if you want

79
00:05:37,060 --> 00:05:38,530
the information you can use to put.

80
00:05:38,650 --> 00:05:40,910
And then if you want delete an object you can use delete.

81
00:05:41,020 --> 00:05:45,940
And these are actually going to be pretty simple to implement with flask restful.

82
00:05:45,980 --> 00:05:49,420
So we're going to need to install a few libraries as we go along so keep that in mind.

83
00:05:49,430 --> 00:05:54,300
You'll see me install these libraries that actually don't come with your requirements text file and

84
00:05:54,310 --> 00:05:59,320
will also need to install postman which is a graphical interface for interacting of arrest API.

85
00:05:59,570 --> 00:06:04,300
No there are actually several interfaces available for this sort of rest interaction and there's actually

86
00:06:04,310 --> 00:06:05,730
command line tools as well.

87
00:06:05,900 --> 00:06:11,690
So if you're already a pro in implementing API of other languages you have your own interface tool or

88
00:06:11,690 --> 00:06:13,340
your own command line tools you prefer.

89
00:06:13,460 --> 00:06:15,330
You can go ahead and feel free to use those.

90
00:06:15,350 --> 00:06:18,110
We're going to using postman because it's free for our purposes.

91
00:06:18,200 --> 00:06:20,060
And it's also pretty simple to use.

92
00:06:20,060 --> 00:06:22,340
All right so here we are at postman dot com.

93
00:06:22,370 --> 00:06:27,230
Keep in mind the layout of the Web site may change in the future so it may not look exactly like this

94
00:06:27,230 --> 00:06:31,730
when you're visiting it but some are on the Web site you should see a button to download the app.

95
00:06:31,820 --> 00:06:36,710
Something I want to mention is that technically there are paid versions of postman and if you scroll

96
00:06:36,710 --> 00:06:42,410
down through their website or go to their pricing plan page eventually you should see that their pricing

97
00:06:42,410 --> 00:06:45,840
plans were just going to use the free one that's totally enough for us.

98
00:06:46,040 --> 00:06:51,790
We're just using this as a simple interface to actually make the automated rest API requests and connector

99
00:06:51,790 --> 00:06:53,400
for flask web application.

100
00:06:53,510 --> 00:06:56,940
Since we're doing everything locally and we're just individuals with small projects.

101
00:06:57,110 --> 00:07:01,700
So keep that in mind reason the free version where we click on download the app and that should take

102
00:07:01,700 --> 00:07:05,240
you to the download page again it might look slightly different from this but you should see buttons

103
00:07:05,240 --> 00:07:10,400
for choosing or platform to postman for Mac placement for Windows and paceman for Linux.

104
00:07:10,400 --> 00:07:15,200
Go ahead and download those and then install it onto your computer and you should be good to go.

105
00:07:15,200 --> 00:07:17,880
Let me show you what it should look like once it's installed.

106
00:07:17,900 --> 00:07:20,580
So once you've installed postman You should see something like this.

107
00:07:20,580 --> 00:07:25,850
Upon opening it where you create new requests collection's environments and there's a lot placement

108
00:07:25,850 --> 00:07:27,410
can do though we really won't be using.

109
00:07:27,410 --> 00:07:28,750
So just keep that in mind.

110
00:07:28,940 --> 00:07:31,080
Definitely not looking at all the features of postman.

111
00:07:31,130 --> 00:07:36,370
Go ahead exit this sometimes asks you to sign in and create a free account so you can do that as well.

112
00:07:36,650 --> 00:07:41,870
And here we have your workspace and we're going to be using this to basically create our or get posts

113
00:07:41,870 --> 00:07:46,510
Reclast delete requests and so on and the requests are all we're going to be entering here.

114
00:07:46,520 --> 00:07:47,350
It's just the local one.

115
00:07:47,360 --> 00:07:49,250
But essentially all we're going to be doing.

116
00:07:49,340 --> 00:07:54,650
And luckily we can actually save requests with some history here in order to just quickly make requests

117
00:07:54,740 --> 00:07:55,850
over and over again.

118
00:07:56,150 --> 00:07:56,710
OK.

119
00:07:56,810 --> 00:07:58,670
So that's it for postman.

120
00:07:58,680 --> 00:08:01,640
If you have any issues downloading it feel free to post Kewaunee forums.

121
00:08:01,640 --> 00:08:04,810
But coming up next we're going to create a very simple rest API.

122
00:08:04,910 --> 00:08:05,550
We'll see you there.
