Go to project: My first API
Okay, so no big deal, but I just made a website using my first ever API!!!! Whaaaat?! That’s official programmer-stuff! I found a Chuck Norris joke database, that supplied a JSONP API that I decided to use. The internet is a crazy place.
The website has two input fields where you can type in your name (or any name), and it will generate a joke with those names based on the Chuck Norris jokes.
Pretty simple stuff, but I kinda love it. Who am I kidding?! I FREAKING love it!
Definitely more API stuff on it’s way from me.
Lessons learned:
- The BF gave me a thorough API lesson, helping me figure out how to use it. As far as I know now, I have to use the so called JSONP APIs and not JSON or other, because they require that I can host the API on my own server, which I cannot. So JSONP APIs will not have to be hosted by me.
- Anyway, I learned about the $.ajax thing, and I cannot explain what it is and why it necessarily works, but in any case it has an object “inside”, that has a bunch of keys (I think it’s called keys) and some of them link to the url of the API. Also it has something called “success” which has a callback function (look at me, using words like callback functions!) that starts IF the data is accessible. If not it also has an error which is an alert.
- I gathered the joke value from the API and replaced the Chuck Norris with a custom first and last name.