You will inevitably bump into references to something called an “API” if you are in the tech domain. You are bound to hear it and you just cannot skip it. Almost everywhere API is used. APIs are being used everywhere. Have you ever wondered what exactly an API is? How important they are? Or how do they help?
We will be explaining today of what API is in simple terms. There are various categories of API. You will also be introduced to different categories of APIs.
So, let’s get started!
What is an API?
Enabling two applications to exchange the data among each other, an API (Application Programming Interface) is a software-to-software interface.
They are used a lot in the real world to create some amazing applications though this might sound a little boring. To connect to The Internet of Things is one key role that APIs will be playing in the future.
Facebook has a public API that allows third-party applications to integrate Facebook as a simple example.
A developer can allow you to log in to an application using your own Facebook account. An application is using a particular API is what is meant through the term “integrate”.
It is just an example when it comes to adding Facebook. Applications integrate into other services as there are thousands of other cases. The following are the other integrations which could be integrated:
- So that you can share your location in a message, WhatsApp integrated Google Maps.
- So that you can log into their applications with your Facebook account, Spotify and many other integrated Facebook allows you this.
- So that you can watch videos without leaving the site some of the other sites have integrated YouTube.
An API os a hypothetical contract between 2 software saying if the user software provides input in a pre-defined format, the later with extend its functionality and provide the outcome to the user software in simple words.
The graphical user interface or command line interface allows humans to Interact with code whereas an Application programmable interface allows one piece of code to interact with the other code so you need to think like this.
On the web, you have one of the most common use cases for APIs. You have certainly used the APIs if you spent a few hours on the internet. All of the services such as sharing things on social media, making payments over the web, displaying a list of tweets through a social handle all use API at the back.
How to use an API
Developers typically install additional packages, or code, for convenience and flexibility as most programming languages already come with the necessary software to interact with web APIs.
There is usually at least one popular framework which is a collection of programs which can be used to create the APIs for any given programming language.
Rails framework is used by the Ruby developers. Additional layers of security can also be an added feature of API as developers can use the packages. With that language’s package manager additional necessary programs are installed.
The basic elements of API:
There are three primary elements in an API:
- Access: Is the user is allowed to ask for data or services?
- Request: This is the actual data or service which is being asked for. There are two main parts of a request:
Methods: The questions which can be asked after assuming whether you have the access or not.
Parameters: The additional details which you can include in the question or response.
- Response: As a result of your request, the data or service.
Categories of API
An interface to either a web server or a web browser is a web API. For the development of web applications, these APIs are used extensively. At either the server end or the client end, these APIs work. Web-based API services are provided by Companies like Google, Amazon, eBay.
Twitter REST API, Facebook Graph API, Amazon S3 REST API, etc are some of the popular examples of web-based API.
Offering the functionality of various OS features that can be incorporated in creating windows or mac applications there are multiple OS based API.
Cocoa, Carbon, WinAPI, etc are some of the examples of OS based API.
Using the API calls to the database, interaction with most of the database is done. To pass out the requested data in a predefined format that is understandable by the requesting client, these APIs are defined in this manner.
Thereby enhancing the compatibility of applications with the various database, this makes the process of interaction with databases generalized. They provide a structured interface to the database as they are very robust.
Drupal 7 Database API, Drupal 8 Database API, Django API are some of the popular examples.
To the various hardware components of a system, these APIs allows access. For establishing communication to the hardware, they are extremely crucial. It makes possible for a range of functions from the collection of sensor data to even displays on your screen due to this.
The Google PowerMeter API will allow device manufacturers to build home energy monitoring devices that work with Google PowerMeter for example.
QUANT Electronic, WareNet CheckWare, OpenVX Hardware Acceleration, CubeSensore, etc are some other examples of Hardware APIs.
How does an internal API work?
Although the company can choose to make portions of it accessible to the public, an internal API is one that is used within a company or organization.
To share data and business logic across platforms which are web, iOS, or Android applications, users within that organization can leverage an internal API.
For example, the company’s rules regarding communication between a user interface and a database. An internal API is likely to be present in any company with both web and smartphone apps.
Seamless which is a food ordering service has web, iOS, and Android applications. To request that action would be performed, like placing an order as well as to request data like the details of a user’s most recent order, all the three platform uses an internal API.
To internally share data and business logic across different devices, this internal API allows Seamless to have this functionality.
The operation of External API
Allowing individuals and companies outside of the organization to develop applications using its services many organizations provide external and sometimes limited APIs. There may be registration, payment, or other limitations which are involved depending on the external API.
The New York Times provides an extensive external API that is free and requires registration which developers follow certain guidelines for example.
Allowing developers to embed maps in their websites and applications as well as retrieve directions and estimated travel times os what Google Maps also provides the APIs.
Google Map’s API is used in Lyft. Yelp Business APIs enables users to find businesses which are the other popular external APIs. To retrieve weather data OpenWeatherMap API is used, and to determine emotions in images, Microsoft Azure Emotion API is used.
To create their own mashup applications like the one that uses the Yelp Business API to find top-rated coffee shops in a neighborhood and displaying them on a map with custom icons through Google Maps API are all done by using external APIs.
Background of Beginner API App
Say suppose that you are an aspiring software developer and you are designing your own app. You can name this application as MyAPIAPP. To obtain the maximum benefit from social networks is what the goal of MyApiApp is.
By viewing the statuses of friends on all networks on one screen for example. On all of a user’s social networks, MyApiApp shows the most important news of everyone.
MyApiApp application has to access the functions of Facebook, Google+, and LinkedIn for this. We will be using their APIs to do this.
Difference between an API and a Library
The interactions between various entities are defined as an API is a set of rules. The interaction between the two software is what we are specifically speaking of.
Denoting the area of the library which is actually accessible to the user from outside, even a library also has an API.
Walking through an example
Data science APIs public for people like us to build amazing projects with only a few lines of code is what IBM Watson has made certain of. We will be looking at one such amazing API offered by IBM called Personality Insights here.
In JSON, HTML or simple text format this API takes the inputs. To the person whose personality interests you the input contains the text. Tweets, daily experiences, applications, opinion, etc of that person is what it would be like.
Containing the information on various social traits of that person, the output generated by the API is in the standard format of JSON or CSV file. Instead of coding the whole functionality yourself, the developer only needs to display the generated file to the user.
To analyze their personality traits you can choose either the tweets or replies of the famous personalities. Based on the input that you want to provide and analyze the personality traits of that person the text can also be customized.
On top of this API, you can integrate this API in your code as well as build an application.
The 5 APIs which every Data Scientists should know
- Facebook API: To a large amount of data which is generated every day, Facebook API provides an interface. A massive amount of data is produced through the innumerable post, comments, and shares in various groups and pages. A large number of opportunities for analyzing the crowd are provided by these massive public data. To use the Facebook Graph API with both R and python to extract the data, it is convenient.
- Google Map API: One of the most commonly used API is Google Map API. From their integration in a cab service application to the popular Pokemon Go, its application varies. You can also use this API for creating the distance feature in your data sets as well and this is the fun part here. You can also check out their complete integration.
- Twitter API: Twitter data can be accessed using the Twitter API as well just like Facebook Graph API. The tweets containing a particular item or even a combination of terms, tweets have done on the topic in a particular date range are all the data which you can access made by any user. For performing tasks like opinion mining, sentiment analysis, Twitter data is a great source.
- IBM Watson API: A set of APIs for performing a host of complex tasks such as Tone ANalyzer, document conversion, personality insights, visual recognition, text to speech, speech to text, etc by using just a few lines of code is what IBM Watson API offers.
- Quandl API: For the specified date range, Quandl lets you involve the time series information of a large number of stocks. It provides a great resource for projects like Stock price prediction, stock profiling, etc by setting up of Quandl API which is very easy.
Check out the technical details of how APIs work for beginners
You will want to know a little bit about the technical details of how APIs can communicate to services even if you are just starting out. Different APIs will communicate in different ways is one problem.
There are four different types which come under APIs. The most common type is RESTful.
SOAP – Simple Object Access Protocol. In the form of an XML file, these exchange data. This is a fancy kind of HTML Table document.
XML-RCP – You call it using XML and it returns XML to use these kinds of APIs. This standard was developed further and it became SOAP.
Communication between applications is done using the underlying HTTP protocol in RESTful APIs. Many developers are already familiar with it as HTTP is widely used on the internet.
This is the reason why all true web address starts with either HTTP or HTTPs as a matter of fact. The most public-facing version of making an HTTP request is what it means on opening a web page. To interact with Program Interfaces, RESTful APIs can also use the protocol.
It sends an HTTP request to the Facebook servers so that the MyApiApp application can access Facebook Feature. It is specified which function of the API the application would like to use in the HTTP request.
You can check out the four major HTTP request methods:
- GET – Fetching data
- PUT – Editing the existing data
- POST – Adding new data
- DELETE – Deleting data
Using one of these methods then the Facebook servers will process the given request after you have sent an instruction to Facebook. Facebook will send back your requested data as long as valid inputs have been given.
How the data has to be formatted in the request and how to call the request is not uniform between APIs or programming languages, unfortunately. With the Google Maps API, we can give an easy interactive example.
You get a JSON request back which is an easy to read format for machines when you use the Google Maps API.
This ensures a degree of protection against abuse for others on the one hand.. If a provider over abuses an API by making say a million calls every minute then the API will become slow and unstable for everyone else is what the reason is.
With the API, this is a developer authenticating themselves. You will also have authentication from the user of the app on the other hand. On a service, this is when a user allows access to their personal data.
On a service, this is when a user allows access to their own personal data. We will be asking permission from a user to access their own personal newsfeed with this.
There are different types of authentication that can be done to make users less wary about giving their personal data to an application.
HTTP Basic Access Authentication. Since it only requires a username and password, this is a very basic form of authentication. In the header of the HTTP request, this is transmitted.
As the user data is only weakly encoded and offers no encryption and therefore offers only a minimum of security as this is the worst kind of authentication.
OAuth 1.0. They work with things called tokens and this method provides a greater degree of security. To an individual user, a token is a unique string that can be assigned.
MyApiApp can request a token from the user through the form of a Facebook login button for example. This process would very much look like downloading an app from the Android App store to the user where a list of permissions the app requires is provided.
Most services rely on OAuth 2 in the meantime due to the complexity of OAuth 1.
OAuth 2.0. To the OAuth 1.0, OAuth 2.0 is more than just a simple upgrade. THat operates in a completely new way as it is, in fact, a new protocol. To improve interoperability as well as safety the main goals of OAuth