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