Consuming HTTP Services in Python Transcripts
Chapter: Consuming RESTful HTTP services
Lecture: Exploring the Basecamp HTTP API

Login or purchase this course to watch this video and the rest of the course contents.
0:02 Let's look at a real API, this API is going to be the latest new API, you can see modified just 25 days ago, and and created eight months ago,
0:13 so it's quite new for Basecamp. So, Basecamp is a project management site that is pretty well known in the tech,
0:20 especially the web industry for a couple of reasons, so it was created by this company called "37 Signals" and they were a web design company,
0:29 and it turned out their product Basecamp was way more popular and profitable and interesting than actually just being a web consulting company,
0:36 so they basically started selling Basecamp as their main thing, they just built it for themselves internally,
0:43 and it's also notable because this is where Ruby on Rails comes from, DHH and Jason Fried and the guys at 37 built Basecamp
0:53 and they said oh we have this really cool unique way of writing web apps
0:56 let's extract that as a framework and we'll call that Ruby on Rails, so that's all good. There is no more "37 Signals" anymore
1:01 because they just renamed their company name to Basecamp, after a while which is pretty interesting, but let's look at their API,
1:08 this is pretty new, we'll go over here and actually pull up some details
1:12 that I have already gotten us too, so we can go check out what are called Basecamps,
1:15 you can see, recently updated by DHH and we can do things like a get request,
1:20 so there is an API url and they are just going to use the short relative url, so if we want to get all the Basecmaps, we can just do get/projects
1:30 and they have everything returning json and make it super explicit they say .json, okay.
1:35 So what else can we do, so if we want to read data about the projects we do a get,
1:40 if we want to read specific, here is the list of projects that come back, if we want to get a particular one, let's say one with id 1,
1:47 we issue a get request against projects/1/json, okay, and then, we get information back here like so, right,
1:56 so when it was created, its name, its description and so on, and so on, so lots of information about that project.
2:03 On the other hand, if we want to create a project, or a Basecamp, just like I said, we are going to use a post to create something,
2:09 we don't know what its id is going to be, it's going to be generated by the server,
2:12 but we know we want to make one so we are going to do a post against projects.json and this is the data that we are going to send,
2:19 just the required data, the name, the description, and then of course, this stuff that is up here will all be generated by the server,
2:24 and presumably returned to us. We also might get a hey, error, you are not allowed to create one of these,
2:30 you are out of space or whatever, the other notable thing to look at is look at the use of the status codes, instead of just always returning 200
2:38 and maybe returning 200 response code, with an error that says sorry, they are actually returning status codes that mean specific things,
2:48 so a 201 specifically means created so you should look for that in this example. A 507 specifically means insufficient storage,
2:56 and they are using that to represent the status code meaning of this error and they give you text, just so you also know.
3:02 Let's see, there is a few other things we can check out here, if we want to update, no surprise, we are going to do a put against that thing
3:09 and this will replace the name and replace the description supposedly, this is going to come back with a 200 and say yeah that worked, and again,
3:15 we are going to do a delete, so we are going to come up here and if we want to do a delete to this thing, and the status code is 204,
3:21 no content which is typically the agreed upon status code for delete. So, this is just the project management side of Basecamp
3:29 or the API for managing projects and Basecamp which they call Basecamps,
3:34 but there is lots of other pieces, you can scroll down and see what we have here, they have Basecamps, the have comments, documents
3:41 but the whole API is very restful and it makes strong use of URLs that point at nouns
3:47 and leveraging the http verbs against those nouns to have meaning. Alright, so in the next section we are going to work with the surface
3:57 that I've created that lets us do all sorts of modifications, create stuff, update stuff, delete stuff and so on,
4:03 and we are going to see how to take this idea and use it on the client side.

Talk Python's Mastodon Michael Kennedy's Mastodon