December 15, 2020
You may be familiar with the concept of APIs or you may even be a developer who creates and employs them on a regular basis. But have you ever wondered: How do APIs work, exactly? Having fundamentally transformed the way developers write applications, APIs introduced ease and fluidity in operations that used to be reserved for those highly trained individuals. Let us explore their precise functions and how they can help business users get more done, more quickly, all without having to learn coding skills.
Before we answer the question: “How do APIs work?” some basic definitions may be in order. Though we hear much about how valuable they can be, explanations as to what APIs truly are less common.
Application Programming Interfaces, or APIs, provide a means of having two applications interact. This software intermediary acts as a messenger that delivers requests to providers, collects the response and sends it back to where the query originated from.
What makes APIs so essential is that they define functionalities that are not dependent on their own implementation. This means that if definitions and implementations vary, these functionalities still don’t compromise each other. In other words, APIs provide building blocks with which completely new programs can be developed much more easily. Instead of having to start from scratch every time they wish to tweak their program, APIs save developers from having to rewrite any bit of code that already exists and make it available for use again and again. This increases their productivity many-fold and gives them the ability to get much more creative without having to worry about commodity functionality, which APIs cover perfectly well.
How do APIs work and achieve such efficiency? A principle called API abstraction is at the heart of it all. It is an advantage because it allows for the decoupling of consuming applications from a service’s infrastructure. This prevents applications that rely on an API from noticing any alterations to the infrastructure behind an endpoint, so long as the exact specification for what the service provider delivers to the endpoint is not subject to change.
This benefits service providers in terms of flexibility as they can tailor their offering however they please. For instance, the infrastructure behind the API (cloud-based virtual servers vs physical, data center-based servers) can be switched around without any consequences.
How do APIs work in more concrete terms? You could imagine a situation where you wish to eat at a restaurant. In this scenario, the kitchen, which will prepare your delicious meal, could be considered as the provider. However, someone needs to let the chefs in the kitchen know what food you want them to cook, and then bring the dish to your table: this is the waiter’s job. You can think of APIs as the waiters of the online world.
How a REST API work.
Now that we’ve answered the question: “How do APIs work?” the next step would be to wonder what they can actually do. It is important to realize that the number of APIs available in modern browsers and throughout applications is absolutely huge, giving developers a wide array of options for things to code.
The most commonly used API is a REpresentational State Transfer or REST API for short. Many of the leading companies like Facebook, Google, Twitter, Instagram, GitHub, or others all use REST APIs to allow third parties to access the data they make public. Usually here's what happens: you make a call from a client to a server and you get data back over the HTTP protocol. For example, if you want to showcase the latest tweets from your Twitter account on your website, you can make a call to Twitter’s API and it will return data with your latest tweets. Congratulations, you have made your first API request!
But when you make an online payment, it's an API that processes your credit card payment from Visa or Mastercard to your vendor. It's also APIs that get the price of flights from multiple airlines for flights comparators, for example.
Client-side storage APIs are another increasingly widespread solution that allows for data to be stored on the client-side, potentially making it possible for the app to run offline or to save its state between page loads. One could also cite APIs that fetch data from a server, graphics manipulation APIs, audio and video APIs, and device APIs.
Now you might be wondering, what types of requests can you make using a REST API? There are several methods that you can make:
GraphQL is another way to query for your API. GraphQL APIs follow the same set of constraints as REST APIs, but it organizes data into a graph using one interface, for more flexibility and efficiency.
When you use a GraphQL API, you get exactly what you need, nothing more and nothing less, with predictable results. It results in faster and more stable apps because they control the load of data.
Comparison between REST and GraphQL
Building a new API, as many projects do, starts with a plan, which helps determine the best tools to utilize for the job. To begin, a reliable, flexible, open-source headless content management system such as Strapi provides a central platform from which one can select their favorite frameworks and development tools. Strapi supports both GraphQL and RESTful API and allows developers to use Node.js to create and manage content through a convenient Graphical User Interface. From there, they can create a database schema, collections, organize documentation plugins, manage authentication, set up permissions, and more. Having full control over both back-end and front-end, developers can get truly creative.
How do APIs work at supporting ever more advanced technologies? With the rise of the API economy, entire business models are emerging. Predictions include a better API experience on mobile devices, business models centered around event-driven APIs, micro-services for API delivery, and better standardization. The future is exciting!
If you want to learn more about Strapi, check out this article explaining how you can integrate anything to Strapi
Sign up for the Strapi newsletter to keep up with the latest news from the Strapi community!
Introducing the API Documentation (Swagger) Plugin on Strapi
December 20, 2018
There often seems to be two distinct positions when it comes to the GraphQL vs REST battle. In this article, we will look at the differences and similarities between both solutions and compare their benefits and limitations.
October 15, 2020