What We're Going to Build2:17 with Kenneth Love
Before you can start building your API, you need to know what data it's going to make available and what actions each resource will accept. Let me walk you through those things before we get down to the nitty-gritty code.
[MUSIC] 0:00 Hi everyone, I'm Kenneth and I'm a Python programmer and teacher here at Treehouse. 0:03 If you're a fan of Flask, you've probably taken our other two Flask courses. 0:09 If you haven't, I highly suggest you take at least Flask basics. 0:13 I'll put a link to it in the teacher's notes. 0:16 This course is going to be a little different from both of those though. 0:19 Because we're not going to be building a web site. 0:21 We're going to build an API, 0:24 so I guess you could say we're building a web service. 0:26 Web APIs are a way for other websites, mobile apps, desktop apps or 0:28 even your own site to use your data in a safe secure and sanitized way. 0:34 Users don't have to try and scrape data off of your website and 0:39 then scramble to fix their data gathering tools whenever you update your site. 0:42 And you don't have to worry that they'll somehow scrape or 0:45 distribute sensitive information. 0:48 It's a win win. 0:49 Our API is going to take advantage of the REST design pattern, 0:51 which I covered in REST API basics. 0:54 Again if you haven't seen it, I'll link to it in the teacher's notes. 0:57 Our rest API is going to be for a service that collects online tutorials and 1:00 reviews for them. 1:04 You could go on there and submit your favorite Python courses, wink, wink. 1:05 And then people could leave reviews about them. 1:08 In fact, I have a few reviews right here. 1:11 All right, I guess we can save them for another time. 1:14 Let's talk about the design of our service. 1:18 At /courses, we'll let users use two methods. 1:19 Get and post. 1:23 Get. We'll get back all of the existing courses 1:25 and post will add a new course to the collection. 1:27 Then at /courses/5 for example. 1:29 We'll provide three methods. 1:33 Get, put, and delete. 1:34 When you get a course with an ID, you'll get back just that course. 1:36 If you put to the course, you'll update it. 1:40 And as I'm sure you can guess, sending a delete to a course will delete it. 1:43 Our second resource will be at /reviews. 1:48 Get and post here will work just like they do for /courses. 1:51 Get, put and delete on our review with an ID like /reviews/15 will work like 1:54 they do for courses, too. 1:59 We'll also end up making a third resource before the course is over. 2:01 But these two are plenty for us to get started with. 2:05 Before we do that though, I think this is a great time to go over these reviews. 2:08 All right, fine. 2:13 I get it, it's tacky. 2:14 I should just give up. 2:15 On the next video 2:16
You need to sign up for Treehouse in order to download course files.Sign up