Web APIs are everywhere. There has been a substantial growth in interest in APIs. ProgrammableWeb, a reference website that maintains a directory of public APIs, reports that the number of APIs have grown from 8000 by the end of 2012 to 9000 as of June 2013. This is a tremendous growth rate, especially coming from 105 in 2005. Mashery, a leading provider of API technology and services for several brands like USA TODAY, Comcast, Hoover's, Klout, Associated Press, Rdio, and Travelocity, also has several resources and case studies showing the success stories as a result of API usage. One of the major factors contributing to all this is the growth of mobile applications.
Web APIs are at the heart of most mobile applications. If you have written an app, a website or any web service, you have most likely worked with web APIs. Let's suppose we are building a note taking app that needs to work on desktop browsers, phones and tablets. We would want a central data reserve or a server that can not only save but also synchronize data across all the various platforms. Being able to talk to this server is where web APIs come in. Web API is a programmatic interface to access remote data. Having such a defined interface also allows for independent development and distribution of multiple apps that use the same data.
What further spurred the growth of APIs is opening up some of these private APIs for public consumption. Several companies like Amazon, Facebook, Twitter and Google provide public APIs that allow access to their data. This opened up a new breed of applications called maship. The ability to mix data from multiple sources to create a rich interactive experience resulted in several innovative applications. Location based tweets, a collage magazine for facebook, Google and Twitter feeds, music player that combines recommendations and band information by using several available resources etc... are some examples of these kind of applications. This has led to a symbiotic growth of both the APIs and mobile applications.
So, what is a web API?
Web API is a programmatic interface to access remote data over the web. HTTP is the foundation of web as we know it. Web APIs use HTTP to transmit data. In other words, a web API is simply defined by a URL just like any webpage. And just like a webpage, the API can be accessed using standard HTTP request messages. HTTP defines methods like GET, POST, PUT and DELETE to refer to the operations to be performed. APIs use the same methods to operate on the data in server. Thus, taking http://example.com/names as the example URL
GET http://example.com/names indicates that the data is to be pulled from the server
POST http://example.com/names indicates the data on the server needs to be updated
and so on. Unlike a webpage which returns HTML content, web APIs typically return a JSON or XML object with the formatted. The combination of one or more of these methods, the URL and a description of the response is what defines an API.
Let's try this using a real world example. Consider the API for Google Maps' directions service. The base URL for the API is:
You can test the URL by pasting it in your browser window. However, doing so will give you a "Request Denied" message. This is because the API dictates an additional set of parameters as mandatory. Parameters are akin to passing inputs to functions. You can pass one or more of the parameters to the API, by appending to the end of the URL as follows
All public APIs are accompanied by a developer guide defining the required and optional parameters. In this particular example, URL should include values for the parameters - origin, destination and sensor. Thus, an example URL to get driving directions from San Francisco to San Jose would be
The above URL now works. It returns a JSON object that encapsulates the required data regarding driving directions from San Francisco to San Jose. We won't go into details about the response for now. You can refer to Google Maps' developer guide for more detailed information about the API.
Hopefully, this has helped you gain some basic understanding of how web APIs work and how they are used in mobile applications. There is so much more to web APIs. We will be talking about other aspects of API usage such as how to access these APIs, response data, error handling etc.. in subsequent blogs.