Understanding APIs

How did Facebook’s Like button become omnipresent on the Internet, from e-commerce websites to online newspapers? How do companies manage to embed their Twitter timeline on their website? The answer to these questions lies in three letters: API. Behind this obscure abbreviation is a designation that is just as abstruse, Application Programming Interface. In simple terms, what are we talking about?

API: a definition

An API is a programming interface which allows two programs or applications to communicate with one another in the same language and to share data. This data can be transmitted in different formats. Among the most commonly used are JSON, appreciated for its simplicity, and XML, rich and powerful. These data formats determine the structure of information. Each API is built according to an architectural style, that is, a set of constraints that need to be met. The most common are REST (Representational State Transfer) and SOAP (Simple Object Access Protocol), which is based on XML. Today, APIs provide a myriad of services in various fields: video (Youtube), cartography (Google Maps), SMS sending, emailing (YMLP, Mailchimp), weather forecast (AccuWeather), social media (Twitter, Facebook)… Because an example is always more compelling than an abstract definition, let’s take a look at a practical case.

Specific case: the Instagram API

A blogger wants her Instagram pictures to appear on her WordPress website. To prevent her from having to publish them manually one by one, WordPress has to retrieve the data needed from Instagram. To be able to do so, WordPress needs to have access to Instagram’s features. This is where the API comes in: it acts like an intermediary between the two platforms and enables them to interact even though they haven’t been developed with the same technologies. This is what we call interoperability. Via the Instagram API, the client (WordPress) sends the service’s (Instagram) database a request in order to import the pictures. Instagram then sends WordPress a response through the API, and the loop is closed!

Why use APIs?

It is no wonder why developers are fond of APIs: they significantly facilitate their work. They are real time-savers since they provide basic building blocks that can be assembled to build quality realizations. No need to reinvent the wheel! Besides, even though some are not free of charge — or at least in part, such is the case of the Google Maps API — , many of them are free and openly accessible, a source of significant savings.

The API-First strategy, an advantage for businesses

For businesses, adopting an API-First strategy (building the API before developing the website or the application) has plenty of advantages. Among other things, it allows them to:

  • easily develop other websites and applications afterwards which rely on the data provided by the API;
  • have an independent lifecycle for each of their websites and/or applications, possibly with a separate team of programmers for each entity, by centralizing their business logic in the API;
  • facilitate the interaction of partners, suppliers, customers with their data and information system — it is the concept of hypermedia;
  • maximize the interoperability of their applications thanks to the Schema.org format and Hydra vocabulary while improving SEO by simplifying the connection to the business software (ERP, e-commerce platforms, CRM…).

In order to facilitate the implementation of API-First projects, we created API Platform, a PHP web framework built on top of Symfony which is designed to build powerful hypermedia REST APIs in no time. Do not hesitate to check it out, if you haven’t already!