#100DaysOfCode in Python Transcripts
Chapter: Days 97-99: Building JSON APIs
Lecture: Adding the Flask basics

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Alright, so this Flask is coming soon.
0:02 Flask is coming now, let's do it.
0:03 So we're going to import flask,
0:05 and down here, remember, you have to create the Flask app.
0:08 And I'm going to use it like this, so we always see
0:10 the full namespace of flask,
0:12 just so it's really clear what's going on here.
0:14 And let's just build, like, a hello world,
0:16 or welcome to our site, little view method here.
0:20 So let's call this index.
0:22 And you have to add the app.route decorator
0:25 and in here we're just going to put forward slash.
0:28 So that's going to tell it what to do,
0:29 and then we'll just say return hello world.
0:33 And just for good measure, just so we can keep track of this
0:36 in the future, 'cause we're going to run into issues,
0:38 let's add a not found 404 handler,
0:41 and we'll just return the page was not found.
0:46 So that's great.
0:47 And then let's go down here and we'll actually
0:50 have a main method, let's put that right at the top.
0:52 That's my style.
0:54 So we'll say app.run like so.
0:57 And let's even say debug=True.
1:00 That's going to be really nice for us, we'll see why in a bit.
1:03 And then we'll say down here, we'll do our little
1:05 main convention, that is in Python,
1:07 and we'll run the main method if that's the case.
1:10 Whew, okay, is it ready to run?
1:11 Let's run our web app and see.
1:14 Whoa, success.
1:15 We have something here.
1:17 Click on it.
1:19 Hello world, awesome, how about that.
1:20 What if we go to abc?
1:24 Page was not found. Okay, so it looks like both the regular index
1:28 and the not found stuff is working really well.
1:31 So this is cool, and just so you know,
1:33 what this debug=True is it'll watch these files
1:37 and see if you make a change and automatically reload it.
1:40 So let's go to hello world, three exclamation marks.
1:44 Go over here, if I refresh.
1:46 Automatically, I didn't have to do anything.
1:49 Because down here, you can see
1:50 it detected a change in that file.
1:53 Restarting, debugger is active.
1:54 Beautiful.
1:55 Okay, so, this is all really good,
1:57 we got our Flask up and running.
1:59 But this doesn't feel very much like
2:01 a JSON API method, does it?