Hello folks!! You as a developer, programmer or one who have interest to work in technical fields might have heard of this small but very useful three word acronym – Application Programming Interfaces or in short APIs .
First of all, let’s understand the intent behind this article. In general, we have observed that most of the developers, especially students, hear about APIs through “word of mouth”. This happens during hackathons or some related events and they just use some common APIs (indeed which is very good) only for sake of project building.
What students fail to understand is what are APIs? How do APIs work? Why are they so useful and what are their functions? What to do if one gets stuck while implementing APIs during project building? What are different kinds of APIs with some examples?
In this article we will answer all that is necessary to know before implementing APIs while building projects.
What are APIs?
Have you ever wondered or thought about why while making payments on apps like Zomato, Swiggy, Amazon, Flipkart etc, you are redirected to different portals like Razorpay, PayTm, PayPal, Juspay etc without sharing all their data? It is made possible only with APIs.
APIs help to communicate, exchange and leverage each other’s data between the tech systems out there. APIs include majorly three types of elements which are as follows:
1. Procedures (also known as Routines):
Procedures refer to the specific tasks or functions a program performs. For example, Twitter provides a Standard Search API for developers to explore data for analytical purposes.
The protocol is a format or a set of rules used to communicate data between different applications. APIs are a set of protocols or definitions used for building and integrating application software.
Tools can be assumed as a set of building blocks – the components needed to construct new programs and architecture. APIs give you flexibility to simplify design, administration,use and provide opportunities for further innovation.
As the name suggests, API acts as an interface to how software interacts with programmed applications. We are increasingly moving towards “API Economy” or better we can say API-centric world.
To support the fact, Forrester estimates that nearly 40 percent of US-based enterprises will implement a solution to handle the increasing management requirements surrounding the proliferation of APIs across the organisation. There are APIs for almost everything like weather, finance, social messaging, payments, security & authentication and even for Bitcoin.
How do APIs work?
The working of an API can be explained in a simple manner with this example. We can broadly classify a restaurant architecture as : chefs (back-end), customer(front-end) and waiter(API). The customer (front-end) places an order (requests sent) for food to waiter (API) and waiter transfers that order to chefs (back-end), as a result, chefs cook and deliver accordingly (take loading time) and thus waiter serves (gives response) to customer (user).
As we have highlighted the term “requests”. The four most common types of requests are:
- GET: The client makes a GET request to retrieve some piece of information from the server
- POST: The client makes a POST request to add a new piece of information to the server.
- PUT: The client makes a PUT request to edit some piece of existing information on the server.
- DELETE: The client makes a DELETE request to delete some piece of information on the server.
Also, we have marked the term “response” and let’s see what status code represents different responses from API. If the user gets data (successful response from API), the HTTPS Status Code will be 200. Otherwise, if there is any error, it will be one of the 400 status codes.
Following are the general status codes:
100 – Informative
200 – Success
300 – Redirection
400 – Client Error ( 404 is one of them)
500 – Server Error
Types of APIs
APIs can be classified on following basis of:
- use cases
- release policy
APIs by Use Cases
These APIs make the communication between an application and a database management system easier. For example, Firebase is a mobile web application platform that lets developers sync, create, update, delete (CRUD) and store data in real-time in a simple manner, without writing server-side code.
Operating systems APIs
Operating systems also have APIs, for example, Windows API , Linux Kernel User-Space API, Apple (MacOS & iOS) etc.
These APIs interact through a communications network, and generally in most cases it is the internet. Therefore, APIs are usually designed based on web standards or specifically can say Web API. But that doesn’t mean at all that “all remote APIs are web APIs.” The most commonly used remote APIs are Web APIs because they send requests from a web application and responses from servers using HTTP (Hypertext Transfer Protocol). Developers make use of such web APIs in the development of apps or sites, increasing their functionality and making them more practical for the user, like integrating a login method via Facebook or Google, or a very famous example of adding maps using Google Map API.
APIs by Release Policy
Private APIs are mainly used inside one’s organisation, integrating them in systems and apps used by their employees and improving internal operations. Even though, if they appear open to the public, the interface remains available only for those within the organisation, which has complete control over the API. For practice purposes, you can learn & implement it here.
Partner APIs are shared with one or more business partners. An agreement is made between said partner and the publisher. A partner API also adds value to the service and opens up a channel for up-selling. Example: Shopify Partner API.
Public APIs are freely available for any third-party developers. These APIs don’t need to have a close relationship between the user and the publisher, can increase the revenue stream, can help reach larger audiences and build traffic, and can support a lot of innovations and a variety of business initiatives. Basically, an open source version of APIs. You can find most of the public APIs here and can use them for your very next project :).
APIs by Interests
SOAP or Simple Object Access Protocol APIs are web communication protocols and are used for exchanging information and structured data over HTTP/HTTPS. It supports the XML data format only.
As defined in Roy Fielding’s dissertation “Architectural Styles and the Design of Network-based Software Architectures,” APIs are RESTful as long as they align with the following 6 guiding constraints of a RESTful system:
- Client-server architecture: REST architecture is composed of clients, servers, and resources, and it handles requests through HTTP.
- Statelessness: No client content is stored on the server between requests. Information about the session state is, instead, held with the client.
- Cache: Caching can eliminate the need for some client-server interactions.
- Layered system: Client-server interactions can be mediated by additional layers. These layers could offer additional features like load balancing, shared caches, or security.
- Code on demand (optional): Servers can extend the functionality of a client by transferring executable code.
- Uniform interface: This constraint is core to the design of RESTful APIs and includes 4 facets:
- Resource identification in requests: Resources are identified in requests and are separate from the representations returned to the client.
- Resource manipulation through representations: Clients receive files that represent resources. These representations must have enough information to allow modification or deletion.
- Self-descriptive messages: Each message returned to a client contains enough information to describe how the client should process the information.
- Hypermedia as the engine of application state: After accessing a resource, the REST client should be able to discover through hyperlinks about all other actions that are currently available.
Why REST APIs?
The constraints mentioned above may seem like a lot but they’re much simpler than a prescribed protocol as in SOAP. That’s the reason why RESTful APIs are becoming more prevalent than SOAP.
Unlike SOAP, REST isn’t limited to using XML. You can obtain the information in different formats like JSON, XML, CSV, plain text, HTML etc which are parsed easier based on the language you’re using for your application.
Moreover, a new type of API standard namely GraphQL is nowadays emerging. It is a query language and server-side runtime and can be an alternative to REST.
You can build your own custom API, REST APIs for different purposes using different tech-stacks like ReactJs, Strapi, Node.js, Python etc and even can monetise them !!
In order to conclude the article, I would say that once you have got your hands dirty working with APIs and developed projects of your own, you can go ahead and apply for internships as well. Cuvette is one such platform that can help you find internships in the field of your choice, either in remote(work from home) or in-office mode.