Apis

Jun 04, 2013

App Academy W4D2

APIs

If yesterday we spent time looking at and using an API - a great one at that with the Twitter API - today we spent time building an API. A contacts API from a rails application that responds to pings and calls from an outside user. It took a lot of the knowledge that we had from our previous weeks and then leveraged that into a rails product that right now has filled in two of the three parts of the MVC framework. Right now we have something with the model and the controller part filled out. Just the views are left. I am told that we are going to start on those in the rest of the week. I wonder then what the heck we are going to learn next week for the rest of the Rails curriculum!

The Contacts API is interesting despite being very simple because it also implemented a basic concept from the OAuth work that we did yesterday: that of authentication. Paul had always lamented the pains of Oauth so I was very trepident about dealing with it. And then we have to implement our own version of Oauth right here! I was very hesitant about the challenge. However it turned out that the work that we did made relative sense to me. I understood what was going on. Our simple authentication system required that someone had to submit along with their API request a “token” string of random warbling letters and numbers. Then we wrote a method that executes before anything happens within the controller using what rails calls a Before_filter. The rails program then looks up the particular user to which we are doing the action and then looks up their token. Do the tokens match? If yes then go ahead and do whatever you want. Otherwise, we break the whole thing with a hard return false.

You can see the whole project here: https://github.com/jonathanstyu/contact_api

3 Things I learned:

1) How Oauth works, in a very simple and conceptual way

2) How to update attributes for a single object instance

3) How to build a freakin’ API! Is that not too awesome?

Other Things I Think I think:

Spurs vs. heat for finals. I call heat in 6.