You often hear the term API getting tossed around on the web. This acronym often comes with a technology prefix like Web API, REST API, and GraphQL API.
What do these mean?
To understand what these mean, you have to understand what an API is.
API stands for Application Programming Interface
Imagine there are two people in a room and they are trying to communicate.
Unfortunately, one person only speaks English while the other only speaks Chinese. It’s impossible for them to communicate because they don’t understand each other’s language.
Now, a translator comes into this room. This translator converts English to Chinese and Chinese to English. In doing so, the translator helps these two people communicate.
The same analogy applies to APIs.
We have three parties:
- Your code
- Code written by another person
- And a set of rules in between that lets your code talk to the other set of code (and vice-versa).
This set of rules is the translator.
It’s the API.
Standardized APIs
Many APIs have been standardised so it becomes easy for us to use code that others have created.
These APIs are commonly given a name. Examples include:
- Web API
- Rest API
- GraphQL
Each set of API contains different methods of communicating with code.
For example, you have methods that are only available in the DOM in the Web API, such as:
querySelectorclassListaddEventListener
The reason why we can use these methods in every browser is because browser manufacturers follow the Web API.
If they didn’t, we would have to write lots of code to target each browser… which means we have to write a lot of browser-specific code.
// Example code if Web API is not standardized.// This is pseudo-code that illustrates my point. (It doesn’t work).const element = safari.findElement() || firefox.selectElement() || chrome.getElement()So the standardization of APIs is a great thing because it gives us a way to write code that others can use — and for others to write code in a way that we can use.
If you are curious, you can find a list of all available Web APIs methods inside MDN.
Rest, GraphQL, etc.
The prefix (Web, Rest, GraphQL, etc) gives you a way to identify what the API is about.
We already spoke about Web APIs so I won’t cover that again. If you are new to Web APIs, I suggest going through Learn JavaScript to have a thorough understanding of JavaScript and Web APIs.
Rest API and GraphQL are two different standards that have evolved around asynchronous JavaScript.
In the next lesson, we will look at the evolution of API standards to help you understand more about these terms.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson