WEBVTT 00:00.510 --> 00:00.810 All right. 00:00.840 --> 00:06.510 Now that we have the models in place for this app, it's time to start building the API. 00:06.540 --> 00:09.150 And when it comes to building, we really have two options. 00:09.450 --> 00:13.140 The first is to sort of build everything out on our own. 00:13.320 --> 00:17.250 And the second is to use something called the Django Reste framework. 00:17.280 --> 00:25.170 It's not technically a part of the Django project, but it is by far the dominant way that people create 00:25.470 --> 00:26.730 APIs in their projects. 00:26.730 --> 00:31.080 So spoiler alert, we're gonna be creating it using the Django rest framework. 00:31.110 --> 00:32.990 But I want to explore the first option a little bit. 00:33.000 --> 00:35.490 What if you wanted to make an API all on your own? 00:36.060 --> 00:37.260 You totally can. 00:37.290 --> 00:39.240 But this is what you would be getting into. 00:39.660 --> 00:45.390 Like let's say, for example, we want to have a Eurail where someone can view the top posts of the 00:45.390 --> 00:45.720 day. 00:46.110 --> 00:47.940 So they would have to go. 00:48.000 --> 00:48.960 You'd have to go first. 00:48.970 --> 00:49.470 Who are you? 00:49.470 --> 00:55.410 URLs and make like a path for API slash top posts or something like that. 00:55.440 --> 00:55.800 Right. 00:56.190 --> 01:00.540 Then we would have to go and move into the view that we've connected there. 01:00.540 --> 01:05.100 And we'd have to make a view that says, okay, when someone, you know, does a get request here, 01:05.130 --> 01:07.250 then we're gonna go grab all the post objects. 01:07.260 --> 01:08.220 We're going to order them. 01:08.610 --> 01:11.340 And then, you know, those are currently Django models. 01:11.340 --> 01:19.320 We're gonna have to decode those and turn it into Jason that we can then spit back to the user. 01:19.320 --> 01:23.850 And really, that part wouldn't be too terrible, but it just gets worse from there. 01:23.880 --> 01:28.260 So, for example, what happens when someone wants to create one of these? 01:28.770 --> 01:32.310 Let's say they want to, you know, create a post using the API? 01:32.670 --> 01:34.350 Well, we have to know what user they are. 01:34.380 --> 01:39.270 So we have to sort of custom build the authentication here because Django has built in authentication, 01:39.300 --> 01:41.220 but it assumes that they're using a browser. 01:41.940 --> 01:46.800 Once we get past that, we're gonna say, you know, what things do we want them to be able to submit 01:46.830 --> 01:50.460 because we don't want them, for example, to be able to say when it was created. 01:50.470 --> 01:52.410 That's something we should automatically do. 01:53.280 --> 01:56.610 And so we kind of have to, you know, customize how this is all going to come out. 01:56.610 --> 01:58.350 We're going to have to save that information. 01:59.080 --> 02:01.530 Derg, the user is going to be passing us, Jason. 02:01.610 --> 02:06.810 So we take that Jason Decoded, turn it into a model, then save it into the database. 02:07.350 --> 02:10.110 These things are all possible, but it's a lot of work. 02:10.530 --> 02:18.120 And what's so awesome is, like I said, there's an awesome project if you search for Django Rest. framework. 02:20.380 --> 02:22.120 Should be the top result here. 02:22.570 --> 02:24.910 Yes, Jango rest framework dot org. 02:25.390 --> 02:30.110 And this is an amazing project preparing to teach this course. 02:30.130 --> 02:32.950 I really started diving into the Web site here. 02:32.950 --> 02:36.550 And there is so much that this framework can do for you. 02:36.560 --> 02:39.970 And the awesome thing is that it can do a ton of things. 02:40.210 --> 02:42.940 But if you want to stay really simple, you totally can't. 02:42.940 --> 02:46.510 And that's what this course is going to be, as I'm going to show you what I feel like are the best 02:46.510 --> 02:48.130 parts of this framework. 02:48.160 --> 02:53.470 But if you ever want to go deeper after this course, I really recommend going through the tutorial 02:53.470 --> 02:54.190 that they have here. 02:54.220 --> 02:59.340 All six steps, because this will only get you started if you really want to dive in. 02:59.350 --> 03:01.000 If you go hit the API guide. 03:01.600 --> 03:02.370 Oh, my goodness. 03:02.380 --> 03:03.550 There is so much. 03:03.610 --> 03:05.680 So, again, this is bringing back to the point. 03:05.950 --> 03:11.980 The word API is used everywhere, for example, when working with the different functions inside of 03:11.980 --> 03:12.580 this framework. 03:12.790 --> 03:15.880 They refer to that as the API for this framework. 03:16.210 --> 03:18.310 But this framework helps you build an API. 03:18.340 --> 03:20.620 So, again, it can get kind of confusing there. 03:21.910 --> 03:23.680 But we're building a Web framework. 03:23.830 --> 03:27.100 This is an eight of a Web API. 03:27.280 --> 03:29.650 And this is an API for this particular framework. 03:29.680 --> 03:34.150 And we don't don't get too messed up with all the different uses of API out there. 03:34.320 --> 03:34.470 OK. 03:35.110 --> 03:40.570 So now that you've seen this project, I'm again going to show you how to get this all installed. 03:40.600 --> 03:42.990 What I feel like is the best way to do so. 03:43.170 --> 03:44.950 So let's go ahead and move back to our project. 03:45.370 --> 03:50.200 And the first thing that we have to do is install the project via PIP. 03:50.350 --> 03:52.090 So let's go ahead and go to our command line. 03:52.770 --> 04:00.340 I'm going to do PIP install and we have to do Django Rest. framework. 04:01.210 --> 04:04.090 All one word, Django Rest. framework. 04:06.220 --> 04:10.720 Once that is done, we are going to move into our settings. 04:12.280 --> 04:12.710 OK. 04:12.810 --> 04:17.250 And inside of our installed apps, we are going to also add here. 04:17.640 --> 04:21.090 The rest underscore framework. 04:22.950 --> 04:29.250 And really, that's all we need to get the project implemented into our code, like we now have access 04:29.250 --> 04:30.450 to this rest framework. 04:31.230 --> 04:32.940 That is going to be amazing. 04:32.940 --> 04:34.890 You'll see in the next video how we set up here. 04:34.920 --> 04:39.030 And I just want to spend one more second to make sure you're really comfortable with the terms being 04:39.030 --> 04:39.690 used here. 04:40.110 --> 04:43.830 You might be saying, why is this called the jingo reste framework? 04:43.890 --> 04:47.460 Like, what does reste have to do with an API? 04:47.580 --> 04:53.610 So a rest API is basically an API that follows some standards. 04:53.610 --> 04:58.530 And if you go ahead and just Google Rest API, there's some really good resources out there. 04:59.880 --> 05:02.940 And I'll just I haven't even looked at this, but I'm just picking the top one. 05:03.300 --> 05:07.890 You'll basically see that the rest API is sort of follow a certain standard. 05:08.640 --> 05:12.210 And so the big one is that there's certain ways that you can interact with that. 05:12.210 --> 05:17.300 You can use get requests, post requests, puts patches deletes. 05:17.310 --> 05:18.420 There's technically more. 05:18.780 --> 05:23.120 But there's this whole sort of style about how you get to particular resources. 05:23.130 --> 05:30.060 And the big thing when it comes to rest API is that they should be the system that is providing the 05:30.060 --> 05:34.980 API and then the system that is consuming the API, meaning getting data from the API. 05:35.580 --> 05:38.500 They should be able to work independently of each other. 05:38.520 --> 05:41.970 It's not like one's always waiting on the other for another thing to happen. 05:43.290 --> 05:49.080 That's the theory called stateless, meaning that, you know, these things can work independently of 05:49.080 --> 05:53.520 each other with lots of times that have passed or could be right back next to each other. 05:54.540 --> 05:55.500 You'll see all of that. 05:55.530 --> 06:01.110 So anyways, if you want to get more into it, there's those different methods that I'd just talked 06:01.110 --> 06:01.500 about. 06:02.640 --> 06:06.960 And as it says here, these are the crud functions, meaning that get is when you're trying to read 06:06.960 --> 06:11.670 something from an API post is when you're trying to create something in an API. 06:11.730 --> 06:18.810 So, for example, get would be when we are trying to list out all the, you know, posts from the Zap 06:18.820 --> 06:23.910 It site in a post request is when we want to create a post. 06:23.970 --> 06:26.220 I know that's maybe not the best name there. 06:26.220 --> 06:26.550 Right. 06:27.090 --> 06:30.900 But when we're submitting a link write creating a post, we're gonna use a post request. 06:31.230 --> 06:34.770 If we want to update something, we're gonna use a put or a patch. 06:34.830 --> 06:38.610 And if we want to delete something, then we use the delete method. 06:38.820 --> 06:40.020 So anyways. 06:40.890 --> 06:44.700 Now, you know, the thing that we're gonna be using is the Django rest framework. 06:44.760 --> 06:48.110 Hopefully you have a better idea of what Rest. API is. 06:48.220 --> 06:48.730 Ah. 06:49.170 --> 06:55.080 And we now have it installed into our project, so we're gonna go ahead and create our very first API 06:55.080 --> 06:56.820 call in the next lecture.