RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Welcome to the course
Lecture: The power of APIs

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Hello and welcome to RESTful and HTTP APIs in the Pyramid web framework. This is your host, author, instructor Michael Kennedy,
0:12 and I'm really excited to share all the way is that Pyramid makes an awesome RESTful API platform. Let's start with a quick overview and big picture
0:21 of where we're going and the power of APIs. So we have our web applications, it's running over here in some servers
0:27 probably has a web app section, probably talks to a database, right. Now, people are going to come using their browsers and make request to our website
0:37 so maybe they're over here on the Macbook or they're on their phone and they're going to request directly to our HTML pages,
0:43 that's going to talk our database, great stuff comes back, right, here's our page, you can watch our courses if this is a course site, whatever right.
0:51 Now, however, what if we have a native app what if we have other servers that want to talk machine to machine,
0:58 technically we could use web scraping but it's really a bad idea, this is not the way it should work- to get at that data;
1:05 instead, we want to set up a separate channel, specifically for these types of systems. We want to set up an API, probably http talking json,
1:14 but as we'll see there's a lot of options here and maybe we want to vary that as well. So now, if we have this API, our native app can pull the data
1:22 in a very efficient format and drive the native app itself. Similarly, our servers might be able to talk directly to our server using this API.
1:32 So, this is one of the primary reasons that we want to create APIs is we want to take our website or our data and expose it to things
1:39 not just for humans, but for machines, for applications, for other machines and so on.
1:45 Let's look at another example. Here we have a big monolithic web app, this big blue cube and it's just one giant web application.
1:52 One of the trends these days is to create more smaller services, often refer to as micro services,
1:59 so maybe we want to break the functionality of our app up into little pieces, maybe one of these is in charge of user authentication and login,
2:06 one of these little services of separate web app is in charge of charging credit cards, one does logging,
2:12 one pulls back data from some API elsewhere, things like that; how do these talk to each other?
2:19 Well, very much like our native app, they're going to use services to glue these micro services together,
2:25 so if you want to build awesome APIs using the Pyramid web framework that's what this course is all about, and it's very comprehensive,
2:34 it turns out that we're going to cover pretty much all the things you might want to do with APIs. What exactly are we going to cover?
2:42 Good question. Let's start the beginning. We're going to talk about why http and why the restful principles
2:47 behind some of these services are useful, and we should follow them. Then we're going to start by creating our initial web application.
2:53 At this point, there will be nothing API specific about it, but APIs run generally inside web applications,
2:58 they just talk a little bit differently than the standard web app does. We'll write our first http service, and this is going to be
3:05 a read only service that exchanges jasn only. We have a couple of end points and we'll do some interesting things here
3:11 but we're not going to create new data, we're not going to modify data, things like that, it's just going to be read only.
3:17 Then, we'll take a little bit of a diversion from the server side to look at two ways in which we can call these services;
3:22 we're going to see how we can call the service that we just created with Python,
3:26 and also how to consume it within our web application using Javascript. Next step, we're going to build a nearly restful service,
3:33 and I say nearly because describing something as a restful service or not it's not a boolean answer, it's more like a spectrum, right.
3:41 So we'll go most of the way, let's say 85, 90 percent of the way towards what you might consider a restful service at this point.
3:48 And then, one of the things we're going to add is the ability to have more than just basic json or HTML responses;
3:54 what if we want csv, what if we want images, what if we want xml, we'll see how we can take what is built in a Pyramid and extend it
4:00 to add all these different response types. Once you have multiple response types, maybe you want to let the client, not the server
4:08 decide what response it's going to get. So with content negotiation we can look at what except type,
4:14 what content type the client is suggesting that they get, so some clients will say I prefer json, we can configure our system
4:22 through content negotiation to automatically return json objects. Now if the same services called the same API and everything,
4:30 but indicating that you'd like to get say image, maybe we'll return an image instead of json, right.
4:36 So we'll see how that works in this content negotiation section. At this point you're going to see that or APIs while working wonderfully
4:42 are going to be quite busy, there is going to be a lot of stuff going on inside those API methods, with validation, with object creation,
4:50 with interacting with the stuff coming off the wire, transform it and so on, and we can move much of that to isolated classes
4:58 that are dedicated specifically to managing this, and we'll have much cleaner
5:02 separation between our validation and the actual implementation of our API. So, we'll do that with this thing I'm calling view models.
5:10 At this point, we'll have been working with just fake data in memory, but it's time to get real and have a real database
5:17 with persistence and all those sorts of things, so we're going to be adding sqlalchemy talking to a sqlight database here
5:24 and doing proper inserts and transactions and all that sort of stuff at this level. So we'll do a quick into to sqlalchemy
5:30 and then we'll convert our in memory model to a data driven database model.
5:34 In addition to real data, we might want to restrict who has access to do what so we'll see how we can add a level of authentication to our services.
5:42 Finally, we probably want to figure out what has happened on our API what are people doing, are there any errors,
5:50 could I get notified in real time of any server side crashes. So in this chapter, we'll see all the techniques and tools
5:58 we can use to make that happen. So, at this level, we pretty much have a really nice working application but how do people get to it?
6:06 Well APIs live out on servers, on the internet, right? So the next thing we're going to do is focus on deployment,
6:12 we're going to create a Linux server, set up nginx and micro wsgi to serve this in a very realistic and high performance way.
6:19 And once we get everything up and working, we probably want people to consume our API so we'll talk about some of the options and techniques
6:26 for documenting our operations. And that's what we'll cover in this course, I think this is quite comprehensive
6:31 and I hope you find it to be really interesting and engaging. Thanks for joining this course, now let's get your machine
6:37 all set up so you're ready to follow along.


Talk Python's Mastodon Michael Kennedy's Mastodon