What is an API?

Published: 07 December 2023
on channel: Erik Wilde
62
2

What is an API? API stands for "Application Programming Interface" and in a nutshell is a way how computer applications can communicate. We will look at two typical examples, explain how APIs help to make this happen, and also look at popular technologies for APIs. Stay tuned to learn more about APIs!

Let's start with two examples. We have picked them to represent two typical areas where APIs are used today.

The first example is something you are using all the time: Mobile apps. Most mobile apps don't just run on your phone, they also talk to a back-end application. This connection from the mobile app to the back-end uses whatever network is currently available, most of the time it's either the mobile phone network or your phone being connected to a wireless hotspot. Regardless of the underlying network technology, the app on your phone always communicates with the back-end in the same way. The language that they are using is defined by the API that the back-end provides. One advantage of this is that you can have one back-end that is used by different applications, for example by iPhone and Android versions of a mobile app. In this example the API is used to connect what often is called a front-end, which is the mobile app, and the back-end. The API defines how the app and the back-end communicate. For example when you look at Facebook there is one API function that allows the phone to post an update to your timeline. And there is another function where the phone downloads new entries in your feed to show them to you. And of course there are many other functions as well. The API in essence is the "language" that the app and the back-end use to communicate with each other.

Now let's switch to our second example. When you're using a Web shop and the store is asking for your phone number to send you tracking information for your delivery, they will not be sending these messages via the phone network themselves. Instead, they will use an external service through an API (for this example, Twilio is a popular choice) that allows them to easily send messages to phones. Twilio's API works in a way where the shop sends your phone number and the message they want to send you to Twilio, and Twilio will make sure that the message gets delivered to your phone. This way, the shopping site does not need to get involved with the details of how to send messages to phones; Twilio handles that for them for a small fee per message. In this case, the API is between two back-ends and not directly visible to you. This is how APIs make it easy to use capabilities that are provided by a third party such as Twilio. And because this is such a useful capability for many developers to use, Twilio has grown into a multi-billion dollar company. In this case, the API also is a language, but it's between business partners: One providing a service such as sending messages and the other using that service for a fee.

Now that we've seen two typical scenarios, let's dive a little deeper into how APIs work. Whether it's between the mobile app and the back-end, or a Web store and Twilio, the API defines messages that can can be exchanged. In terms of technologies there are different ways how this can be done. Let's look at two popular examples:

For the Facebook app, the API uses a language called GraphQL. GraphQL allows the app to request specific information, for example it could ask to get the last 5 posts of a specific user and the information about how many likes and comments these posts have. The back-end responds with exactly this information which can then be displayed by the mobile app. GraphQL is very good at supporting these kinds of requests, which explains its name: GraphQL stands for "Graph Query Language" and in our example, the query is into the social graph of Facebook. In this case, the very name of the technology makes it clear that an API is a language: It is a set of rules how communicating parties can interact.

For sending phone messages, Twilio provides a REST API that is based on HTTP and JSON. The API uses the same communication protocol that is used between Web browsers and servers, the Hypertext Transfer Protocol. The Web shop sends an HTTP request that uses JSON, which is a simple text-based language for structured data and contains the necessary information which is the phone number and the message to be sent. Twilio accepts this request if it is correctly formatted and performs the requested action. Then it sends a response indicating success or failure. REST APIs are a popular choice for this kind of request/response interactions between API consumers and providers.

There are other technologies as well, but what you can see from these two examples is that APIs come in different flavors. It depends on the scenario and the context which technology you should pick for designing and implementing an API.


Watch video What is an API? online without registration, duration 06 minute 33 second in high hd quality. This video was added by user Erik Wilde 07 December 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 62 once and liked it 2 people.