What is an API? Application programming interfaces explained

API stands for application programming interface, a theory that applies everywhere from command-line tools to enterprise Java code into Ruby on Rails web apps. An API is a way to programmatically interact using a separate software component or resource.

Unless you write every single line of code from scratch, you’re going to be interacting with external software components, each with its own API. Even in the event that you do write something entirely from scratch, a well-designed software program will have inner APIs to help arrange code and create components more reusable. And there are many public APIs that allow you to tap into functionality developed everywhere on the web.

What is an API?

An API is defined as a specification of possible interactions with a software part. What exactly does this mean, exactly? Well, imagine that a car was a software component. Its API would include info about what it could do–accelerate, brake, turn on the radio. It would also include info about just how you can make it do these things. For example, to speed up, you place your foot to the gas pedal and push.

The API does not need to explain what happens inside the engine when you set your foot on the accelerator. That’s why, in the event that you learned to drive a car with an internal combustion motor, you can get behind the wheel of an electric car without needing to learn a completely new set of skills. The exactly what and how information come together from the API definition, which is abstract and separate from the automobile itself.

One thing to keep in mind is the name of some APIs is frequently utilized to refer to both the specification of their interactions and to the true software component you socialize with. The phrase”Twitter API,” for example, not only refers to the set of principles for programmatically interacting with Twitter, but is generally understood to mean what you socialize together, as in”We’re doing analysis about the tweets we got in the Twitter API.”

API as abstraction layer

If it comes to applications, APIs are literally everywhere. APIs go hand in hand with a few of the most fundamental concepts in computer science: abstraction. Abstraction is just a way of coordinating the complexity of a system so that complicated actions can be handled in a simple way. Think of this abstraction like these Amazon Dash Buttons, the battery operated, push-button circuit boards you can use to purchase basics from Amazon.

You order a Dash Button out of Amazon and use an app on your smartphone to associate it with your own Wi-Fi system, your Amazon account, and a product, sayyour favorite brand of paper towels. Then, whenever you would like to order more paper towels, you simply press the button. The Dash Button connects to the Internet and sends a message to put an order on your accounts. A few days after, paper towels arrive at your doorstep.

Like an API, the Dash Button is a blissfully simple interface which hides all kinds of complexity behind the scenes. The ID of the item you ordered should be retrieved from a database. Your delivery address must be pulled out of your account. The closest satisfaction center stocking your paper towels must be decided, then advised to remove a product from the available stock and package this up. Finally, the package must be routed through some combination of airplanes, trucks, and vans along with other bundles in a way that guarantees that all the bundles will achieve their destinations efficiently.

Now imagine you needed to coordinate all of these items as a customer. You’d never order paper towels because it is too complex and time consuming and you have better things to do. Luckily, the whole ordeal is abstracted away from you. There is a long, interconnected chain of computer systems and human procedures that make those paper towels show up at your doorstep, but all you need to think about is pressing a button.

This is what APIs are similar to for developers. They require an overwhelming amount of complexity and define a relatively straightforward set of interactions that you are able to use instead of doing it all yourself. In any software project, you’re likely using tens of thousands if not hundreds of APIs directly, and each of those APIs relies on other APIs and so on.

Public APIs and API integration
APIs are a longstanding theory in computer programming, and they have been a part of developers’ toolsets for years. Traditionally, APIs were utilized to link code parts running on precisely the same machine. With the rise of ubiquitous networking, more and more public APIs, occasionally called open APIs, have become available. Public APIs are outward facing and accessible across the Internet, allowing you to write code that interacts with other sellers’ code online; this process is called API integration.

These kinds of code mashups allow consumers to mix and match functionality from different sellers on their own systems. As an example, if you employ the marketing automation software Marketo, you can sync your information with Salesforce CRM functionality.

“Open” or”public” should not be interpreted as meaning”free of cost” in this context. You still have to be a Marketo and Salesforce customer in order for this to work. But the availability of these APIs makes integration a much simpler procedure than it otherwise could be. (InfoWorld includes a great listing of public APIs you should know about.)

Web services and APIs
You might recall the expression w / eb services in the early’00s and believe the notion of an open API sounds pretty similar. In fact, a web service is a particular kind of available API, one that matches a fairly rigid set of specifications, such as that they be specified in Web Services Description Language (WSDL), an XML variant.

Web services were supposed to be used as part of a service-oriented architecture (SOA). As the Nordic APIs blog explains, that gave web services something of a bad name, as SOAs never quite lived up to their potential. Advances in the methods utilized for service-to-service communications–notably lighter, more flexible REST–also have left web services marginally behind in the sphere of public APIs.

REST APIs
Web services were originally designed to communicate using SOAP (Simple Object Access Protocol), a messaging program that sends XML documents over HTTP. Today, however, most web-based APIs utilize REST–Representational State Transfer–as an architectural style.

REST was formally introduced by Roy Fielding in his doctoral dissertation at 2000. It is a set of architectural elements, layout principles, and interactions employed for building distributed systems which demand media of any sort (text, video, etc.). In its heart, REST is a style of building systems that permits flexible communication and display of information throughout the web while providing structure necessary to easily build general purpose elements.

At a REST API, a source might be pretty much anything, but examples include an individual, a list of tweets, and the current results of a search for tweets. Each of these resources is addressable at a resource identifier, which in the case of web-based REST APIs is usually a URL, for example https://api.twitter.com/1.1/users/show?screen_name=twitterdev. When an application requests a resource with the identifier, the API delivers the current representation of that resource to the application in a format which the application can consume, such as a JPEG image, HTML page, or JSON.

Among the big differentiators of REST is that it involves sending data to the requesting application. While this provides great flexibility, allowing the application to do anything it wants with the data, it comes at the price of efficiency. Sending data over the web for processing is quite slow compared to doing the processing where the data resides and then delivering the results.

Obviously, the problem with the”effective” strategy is that systems hosting the data would have to know what applications wish to do with it beforehand. Thus, in order to build an API that has general purpose usability and flexibility, REST is the way to go.

API examples
There are plenty of public APIs available for you to socialize with, many from industry behemoths. The ability to access some stage company’s code programmatically via an API is the thing that makes them a stage, in character. Some prominent API examples include:

Google APIs, which permit you to connect your code to the whole selection of Google services, from Maps to Translate. APIs are so significant to Google that they obtained Apigee, a top API management platform.
Facebook APIs, which permit you to programmatically access Facebook’s social chart and marketing tools. (The company has been restricting precisely what user data you can access via these APIs in the fallout from Cambridge Analytica and other scandals.)
To really get a feeling of how APIs work, let’s do a deep dive into 2: the Java API, that Java developers use to interact with the Java platform, and also the Twitter API, a public API that you would use to interact with the social networking service.

The Java API
The Java API is a library of software components available”out of the box” to anyone who has set up the Java Development Kit. These components implement common tasks and generally increase productivity because developers do not have to start from scratch every time. Among the basic components used in applications is something called a List, which, as you may expect, keeps track of a list of things. The Java API defines what you can do with a List: add items, sort the listing, decide if an item is in the list, etc.. Additionally, it specifies how to execute those actions. To be able to sort the List, you need to specify how you would like the List sorted: alphabetically, numerically descending, brightest to dullest color, etc..

The Twitter API
The Twitter API is a web-based JSON API that enables developers to programmatically interact with Twitter data. Unlike the Java API, that is included in the Java Development Kit, the Twitter API is a web-based API. It must be retrieved by creating requests across the Internet to services which Twitter hosts.

Having a web-based API such as Twitter’s, your program sends an HTTP request, exactly like a web browser does. But instead of this answer being delivered as a webpage, for individual understanding, it’s returned in a format that software can easily parse. Numerous formats exist for this purpose, and Twitter utilizes a favorite and easy-to-use format named JSON. (In case you’re not knowledgeable about JSON, you may want to spend a few minutes reading up on it here.)

Among those basic elements in Twitter is that a tweet. The Twitter API informs you what you can do with tweets: hunt for tweets, produce a tweet, favorite a tweet. It also tells you just how to perform those activities. To search for tweets, you want to specify your search criteria: phrases or hashtags to look for, geolocation, language, etc..

API layout
API design is the procedure by which the”what” and the”how” of an API are devised. Much like anything else which may be generated, varying levels of thought and care are placed into API design, leading to varying degrees of API quality. Well-designed APIs have constant behavior, consider their context into account, and maintain the needs of the customers in mind.

Consistent behavior within an API greatly impacts the rate at which it could be learned along with the odds of developers making mistakes when using it. Generally, APIs that perform similar activities should behave similarly, irrespective of their technical gaps. For an example of an inconsistent API, let us look at the two ways to add a product to a List in Java:

Even though the two methods of adding items to a list do exactly the identical thing, their return types (boolean and emptiness ) are distinct. Programmers using this API now have to keep tabs on which method returns which type, making the API harder to learn and its usage more error prone. It also entails that the code which uses these methods becomes less flexible, because it has to change if you want to change the way you’re adding elements.

Taking context into account is another sort of consistency, although it has to do with factors external to the API. A excellent, non-software example of this is how the principle of the street –right hand traffic or left hand visitors –influences car designs for various nations. Automobile designers take that environmental variable into consideration when locating the driver seat on the right side or left side of the automobile.

In API design, taking context into consideration usually ensures that you’re adhering to commonly accepted best practices and taking inspiration from different APIs your users will likely be acquainted with. Say you’re building a library which provided a new sort of List to a Java application, maybe one that was made to work specifically with very large lists. The API of the List should probably incorporate an add method that behaves in the exact same way the Java List add method works. That way, users can easily embrace your library because they already know how to utilize it.

Understanding your users and keeping their needs in your mind is of extreme importance in API design. Your API will have happy customers if you understand their pain issues and let them avoid that pain. For the same reason, you may choose to break with other principles of good API design. In the event that you were writing a web API, the de-facto standard today is to use JSON as the interchange format. But if your API will be serving scientific users that will be regaining massive amounts of information, JSON is going to be overly verbose and cumbersome to serve them well. As a result, you may opt to utilize a binary format such as GRIB, even though it’s an extremely uncommon choice in the general sense.

APIs are a basic component of software design and they exist at every level of their software stack. They supply a way to define and manage abstractions by telling us what we could do with software components and we can do it. Well-designed APIs encourage efficient, fluid, and simple adoption and use, while poorly designed APIs tend to trigger headaches every time they’re used.

API development
Ready to start in creating your APIs? Check out InfoWorld’s handy listing of no-cost tools for API development, such as API designers, testing and debugging tools, gateways, and full-blown professional API services.

Author: Nhanh Admin