Digital U for a Digital You -- A Beginner’s Guide to APIs
If you're in the Web world, chances are you've heard the term API – but what does it mean? Many simply nod, smile, and move on to the next topic, but for Web developers an API can help you unlock the power and potential of your design creativity.
What is an API?
API stands for Application Programming Interface. Strictly speaking it's a set of rules, commands, or functions, which specify how certain software components should interact with one another.
In this industry we are often referring to third-party APIs, which allow access to data that is normally restricted. Companies like Google, Facebook, and Twitter all have solid APIs that afford developers the opportunity to access, manipulate, and post data to their services using well-defined commands, data formats, and access rules.
These APIs allow developers to create incredible apps, widgets, and integrations, without having to resort to less-admirable methods of accessing data like 'scanning' a web page and parsing the results.
Why Are APIs Important?
An API allows a content provider to define important things including access rules, terms of use, and rate-limiting. Allowing external developers to use your data opens up the door for creative ideas and promotes a marketplace for your data outside of internally developed applications.
Encouraging external developers to be involved with your data fosters community and can help grow engagement with your brand. Strip away the business jargon and the benefit is as simple as this: you can't think of every cool thing that your data will ever be used for, but when give the tools to the world, you may find that a plucky young college student with a cool idea steps in and does it for you.
Standards
The API world can be a lot like the wild west; the rules for creating an API are largely up to the content providers.
In many cases these content providers are only allowing access to certain aspects of their service, so as not to become obsolete themselves (Twitter almost killed their own app by having such an awesome API, they have since scaled back a bit and introduced new rules for developers, that have eliminated a number of competitors.)
There are standards that define how a well-behaved API should behave: REST (representational state transfer), CRUD (create-read-update-delete); and oAuth are all architectures that are being adopted as standards for APIs. These standards define how data is served and received by the server, the operations available to handle this data, and how users and developers are authenticated and receive access to services within an API.
This is not a definitive list by any means. In fact it is woefully inadequate and I could write a series of blog posts about the different technologies and architectures being used to create APIs. But this is not an advanced programming architecture course, this is introduction to APIs.
APIs and Drupal
Drupal, like most other content management systems, is set up to store and source data from a database, not an API. What this means is that out of the box Drupal does not assume that you will be collecting data from an external service for use in your application.
There are a number of community-contributed modules that provide access to external APIs. Unfortunately these are often too scenario-specific or only provide you with a base layer to build upon, rather than a full-fledged solution for sourcing data.
More issues arise when you try to make Drupal behave as if the API content is a Drupal entity (piece of content) as you lose the ability to interface directly with powerful modules like Views and Rules. These are database-driven modules that assume database software is being used to handle data.
All of these problems are solvable with a good developer to help out, but where Drupal really shines is as an API content source.
The Drupal Module Services provides a way for Drupal to act as an API data source. It comes packaged with a REST server and a standard set of CRUD operations for interacting with all of Drupal's built-in entities. When combined with modules that provide access control and interface with other modules (like the oAuth module and Services Views) you suddenly have a very powerful tool for building APIs and allowing external developers access to your data.
The Big Picture
Interfacing with an API is a great road to follow if you want to provide exciting new features, but the path get there isn't always an easy one. In light of the lack of industry standards governing the vast array of APIs available, you will often find yourself developing solutions on a case-by-case basis. But the impact your solutions can have can have is amazing.
Sourcing data from an API can also be a way to build and provide content, but that comes with its own set of challenges as well.
Providing a flexible API, whether for internal or external use, can be a very smart move. In the field of app development using tools like backbone and angular, you will usually find a powerful REST server running behind them to store the data they need to function. There are even modules that build on Services with a focus on mobile app development (see the MASt module). Drupal is a powerful tool in this respect and can provide a complete solution for API development.
Conclusion
Until a one-size-fits-all approach to APIs is developed, you're going to have to rely on your knowledge, experience, and creativity. But that's a great opportunity for you to express yourself within the confines of development – how you use the data received from an API and translate it into something useful for your end-user is the most important result.
In the end, you're acting as a translator: taking data from one source and presenting it in a way that's useful to your client or your user. How you do that is limited only by your ingenuity within the parameters defined by the API.
Comments are open. How familiar are you with APIs? How do you use them and what challenges have you faced with them? Share your thoughts in the comments section below.