Help with learning about APIs

Hi all, does anyone have any suggestions about how to teach myself APIs and JSON better for the intermediate front end projects. I’ve been through the exercises on FCC but still feel very lost when trying to call and utilise information from an API in a project. Anyone got any other resources which they found helpful?

2 Likes

APIs (that is, RESTful API calls) was a topic that I had struggled with for a while, too, though I can’t think of what resources I used to overcome my mental blocks. I eventually got it after going through a project or two and getting a handle on what I need to do and what the result will be. Is there a particular API that you’re trying to work with right now? Can you think of any questions about what you’ve seen?

Here’s a thing I had written about JSON on Reddit. Hope it helps.
JSON stands for JavaScript Object Notation. The secret to understanding JSON is that there’s no secret to understanding JSON. I’ll assume that at this point, you’ve already created some JavaScript objects. If not, go back and review this challenge, Build JavaScript Objects and this challenge Accessing Object Properties with the Dot Operator . If you can remember how to make and read objects, you’re most of the way to understanding JSON.
The point of JSON is that we need a predictable way to structure information that we pass from one application to another, even if they’re written in completely different languages. What I want, as a front end developer, is to be able to request some data:
var user = getJSONFromADatabase('Henry'); //Get user data for user "Henry"
… and then be able to access that data just like I would any other JavaScript object
var userName = user.name;
It doesn’t matter if I got that JSON data from another web form, a text file on my server, or a database somewhere. It’s given to me in JSON. That’s helpful! Here’s what the JSON data might look like:
{ "name": "Henry", "favoriteIceCream": "Rocky Road", "hasReadGameOfThrones": false }
Don’t overthink it. There’s very little difference between writing JSON and making a JavaScript object. There’s no difference when all you’re doing is reading it.

2 Likes

You should check out some videos related to using APIs. The documentation is the key for using APIs effectively. I struggled with using the API as well. I think the way they have shown to use the API in FCC isn’t sufficient enough, you need a little bit more to understand how to utilize them. I saw few videos showing me how to use API then i researched about it more online, built a demo to check whether i understood the concept and now i am going to start with my Random Quote Generator. I feel it would be quite easy to make after you are successfully able to use and understand APIs.Good luck!

1 Like

I also felt I was lacking a solid handle on JSON and APIs when I started in on some challenges that were going to require usage of JSON and/or JSONP. I’m going to try
CodeAcademy’s javascript course and see if that helps. (Specifically looking at Unit 6: Data Structures, Unit 7: Objects I and Unit 8: Objects II)

1 Like

I’ve been having the same issue as @JamesRiall, but your response seems to have helped. Would it be safe to say that JSON is just a standardized way of creating objects, so that programmers can predict how to access data from those objects? :astonished:

That would be a great way to phrase it. The standard works great outside of JavaScript, too. I just installed a tmux plugin written in Python that uses JSON objects for user configuration.

I can’t believe that is all that is going on, but then it is all in the name. JSON should be written as JavaScript Object !!!NOTATION!!! Many thanks @PortableStick!

I think that sounds right (or close). The definitions I’ve read say that it is a standardized text format that stores data as JavaScript objects. It’s not the only structured format that you can use or APIs can return (there’s also xml, csv, etc) but it seems to me the most convenient if you’re using JS to create objects from the data.

@vkg and that is where AJAX comes in? Although AJAX stands for Asynchronous JavaScript and XML it can also process other data formats, such as JSON, right?

Yup that’s absolutely correct. Ajaj would look a bit silly, that’s why they have stuck with AJAX, a lot cooler term. :smiley:

Thanks for the help @kunalgupta05 and @PortableStick! Sorry to hijack your room @JamesRiall, but it helped out a lot!