It will become a lot more clear once you get to the back-end yourself, but the understanding will come with practice. A link is just a link - it points/directs to something else. You aren’t going to use a link at random - when you use a URL, you have a specific destination in mind. When I put freecodecamp.org in my browser, I know I will be given a website. When I put https://www.freecodecamp.org/json/cats.json in my browser, I know I will be given JSON data from an api. It’s confusing at first, but whenever you need to use an API, the documentation will be very explicit what URL to link to. As a beginner, it seems like you just put random URL’s in and it magically works as JSON. The truth is that there really isn’t any magic, but your browser is doing a lot under the hood. If you want I can get a little more technical on why a link is an API, but don’t feel like you have to know the specifics quite yet.
Ok, so more technically speaking, every URL points to a server. Server’s deal with requests and responses. Every time you enter a link in your browser, under the hood your browser is sending a request to that server. When the server gets that request, it decides how to answer it, and then sends back what’s called a response. When you just put in a normal URL like freecodecamp.org, your browser sends a request to freeCodeCamp’s servers for HTML data. The server will then send back HTML data in a response. Your browser than parses the HTML and displays it for you to see. Now, when you do something like
$.getJSON(...), your browser sends a request to a server, but this time the server asks for JSON data not HTML. When the server gets the request, it will see that you requested for JSON data, so it will retrieve and modify the data you need, and then respond with a json file. So basically, the client or your browser is specific on what type of data it wants. When you load a webpage your browser tells the server it wants to load a webpage, so the server sends HTML. When your browser wants data from an API, it tells the API it wants their data in a json file.
API is a confusing term. I simplify it this way - it’s a way to access another service. You don’t have full access to Google’s databases. That would be crazy, even if you were an employee. Fortunately, Google let’s us get data from their databases, or interact with them, we just have to do so in a way they give us permission to do so. They give us an API to their services, so when we want to find where something is on a map, we ask for data from the Google Maps API. If you wanted to send a SMS message or text, that would be pretty difficult to just do out of the blue. Forunately, you don’t have to learn how to do all that, because companies like Twilio help you out. They provide a service of texting other’s, and you can use their api to send text messages to others without having to mess with all the details yourself. API’s are a tool. You can get data from other sources like the weather from a weather API. You can use them to access a third-party service designed to help your application.
Notice how when you click the buttons, it reloads. Every time you hit a button, your browser has to send out a request for new data, and the server will get that data and refresh the page. In other words, it is synchronous. You ask for data, the server sends data, and page is refreshed. Now, take a look at these examples: