RESTful and HTTP APIs in Pyramid Transcripts
Chapter: What is REST?
Lecture: Example service: Basecamp
0:01 The other example of http service that I want to talk about has to do with basecamp. So a basecamp is like a project management system
0:09 you've probably heard of it, it is actually most notable for being the thing that was created from which Ruby on Rails was extracted
0:16 so David Heienmeier Hansson and some other guys created basecamp and they said oh, as part of creating this project,
0:22 there is this really cool thing that we've created with Ruby and we'll pull them out, we'll call that Ruby on Rails, right,
0:27 we're not talking about Ruby now, but it is notable for that. So these guys have been building web apps for a long time
0:32 and they have an interesting take on APIs and I think it's generally really well done
0:37 but it's also interesting on how it's different than many other things. So let's go down here, so here's the Basecamp 3 API,
0:45 it says well how is this different, every request must end in .json that's interesting, they are also using oauth 2 here, and they've renamed
0:53 what used to be called projects to basecamps, okay. Now, notice all of the requests have this access token
1:01 authorization, bearer and then the value of the token, you can see down here they actually give you an example, well, not much of a token, huh.
1:09 But they show you how to store it in your account. Ok, so let's go look at how they use this API to interact with projects
1:15 or what they've renamed to basecamps, so we can get a basecamp, we can get all of them, plural,
1:20 we can get a singular one, we can create, update or trash one. Now, check this out, so they're going to do a get against /projects
1:27 they haven't changed the name because I guess that would be too much to ask for people to change their URLs,
1:32 so /get/projects but they've decided that everything is going to be json and they want to be extra, extra explicit about it,
1:39 so they've had you put a .json on. Now, you might say well that's kind of weird, right,
1:46 that doesn't follow the rules and the thing is when you're making services, there are no rules, that's cool, it's wonderful actually,
1:52 you get to make the rules, right, they've decided this is how you're going to interact with our web service, here's the rules right.
1:58 So what they have decided is .json goes on the end maybe later there's a .xml, unlikely, but possible I guess.
2:04 So you do this get and of course you get json back, you get a list of json objects, all the basecamps, projects.
2:11 You can get a singular one, these are specified by id really more like this id, but you would get something like this,
2:18 you would say /projects/projectid.json okay. That's again a get, let's look down here when I create one I am going to do a post to projects json
2:29 and this is a minimal amount of data you have to pass through, right. You might get an error, you will probably get a 201 created, that's solid,
2:36 but you might get a 507 insufficient storage, in the case where your account is out of projects;
2:43 one of the ways you pay for basecamp is you buy different tiers, and those different tiers have a different number of projects available to them
2:49 so instead of just crashing or something, say not ok, they say 507 insufficient storage, and they pass back an error.
2:57 That's pretty cool I think, if we want to update one, we're going to do a put to that location, again 200 is returned
3:03 because they give back the value, if you want to delete it you just do a delete again to that same url, and this time 204 no content is returned
3:12 if that thing works out ok, if you are able to delete it. So that gives you a good sense for the basecamp API,
3:19 I really like their API quite a bit, I'm not sure I'm sold on this .json but like I said, it's their world they are going to make their own rules.
3:27 If they want .json, that's what they get. But yeah, it's a good API, it's here on github,
3:32 you can check it out just basecamp/bc3-api and you could play around.