Do you really know REST API?
APIs have become an important part of the tech landscape.API stands for Application Programming Interface.
Introduction
Hi folks, API stands for Application Programming Interface, which is a number of definitions for building application software. In this article post, we will explore the history of APIs and why they have become such an integral part of modern software development.
History
The idea of an API was born in the 1950s
73 years ago, computers were a long way off from what they would eventually become today. In the 1950s, computers might as well have been incredibly expensive calculators.
These 1950s computers are developed & started to be used for business-to-business sales. At that time the engineers are facing an issue that collected information on sales at one region cannot be updated to some other region immediately.
So, They found that API is a potential method to facilitate communication between two computers.
The term was first mentioned in a 1951 book written by Maurice Wilkes and David Wheeler called ‘The Preparation of Programs for an Electronic Digital Computer.’
At this stage, an API was starting to exist, but they were limited to simple, command-line interfaces that enabled programmers to interact with computers.
The concept of an API evolved in the 70s
Throughout the 1960s, computers started growing in popularity. The term API was understood at this time as the interaction of a single application with the rest of a computer system.
In 1974 the term API was introduced in a paper called ‘The Relational and Network Approaches: Comparison of the Application Programming Interface.’ It introduced APIs to the world of databases. It became evident that APIs could combine different interfaces to support all types of programming.
After that APIs continued evolving & today. we can say a major part of web-based services depends on APIs.
What is an API?
An API, which stands for application programming interface, is a set of protocols that enable different software components to communicate and transfer data.
An API, or application programming interface, is a set of rules that define how applications or devices can connect to and communicate with each other.
Web APIs communicate via HTTP requests to perform standard database functions like creating, reading, updating, and deleting records (also known as CRUD) within a resource.
Real-world Example of API
Let's imagine you want to know the live weather status of all continents. Think in a logical way then we can try to convert that into a technical solution.
You may make friends on all 7 continents. So, each one of your friends knows the current weather of the continent in which they are currently being. You can tell your friends to call at the interval every hour & update you on the weather status with respective times & temperatures.
It makes sense right now you can know the live weather status of all continents. So, Now if some other person wants to know the weather status. They can call you to ask for the weather status.
Now check the image below for a better understanding.
So, the information from your friend is getting stored in a database. In the world of computers to communicate with another computer we use APIs to process & save the data.
Now the collected data can be used by other computers & clients by asking to give the weather data of a particular continent via API.
I hope you have understood the idea behind the API. If still feels a bit confusing. Just take time to breathe & read once again & try to imagine the scenario.
What is REST?
Representational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web services.
REST was initially created as a guideline to manage communication on a complex network like the Internet. You can use REST-based architecture to support high-performing and reliable communication at scale.
In Layman terms
As we see in the above example. we said that anyone can get information from a server. But how do the public people know How to ask for information? So, the software engineers made a set of rules or styles to build API on global standards.
They named that convention REST. I believe now it makes sense what a REST-API means.
REST-based Architecture
As we know API works on HTTP requests. In HTTP there are five methods that are commonly used in a REST-based Architecture., GET, POST, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete operations respectively.
GET:
The HTTP GET method is used to read (or retrieve) a representation of a resource. In the safe path, GET returns a representation in XML or JSON and an HTTP response code of 200 (OK). In an error case, it most often returns a 404.
POST:
The POST verb is most often utilized to create new resources. On successful creation of a resource, return HTTP status 201.
PUT:
The PUT method is used for updating the resource which has been created earlier & can create some sub-records as per needs. On successful update, return the 200 status code.
PATCH:
The PUT method is used to modify resources. The PATCH request only needs to contain the changes to the resource, not the complete resource should change. On successful update, return the 200 or 204 status code.
DELETE:
The DELETE method is used to delete a resource. On successful deletion, return HTTP status 200 or 204.
I think you may understand the REST -API better. But, You may have a question about what status code 200 & 204 mean. Let dive into it.
HTTP status code
There are 5 ranges of HTTP status codes. Each range defines where the error was encountered and the number defines what the actual error was. They are
1xx: Informational
2xx: Success
3xx: Redirect. The requested page has moved somewhere else.
4xx: Client error. There's something wrong with the way the browser asked for the page.
5xx: Server error. Something went wrong with the way the server tried to send the page.
The HTTP status code are a peice of data that give more infromation on what happend on a given request.It not a book defention just for rememberance.
Conclusion
I hope you have clearly understood the idea behind REST-API's by adopting RESTful architecture, developers can separate concerns and create loosely coupled systems, This promotes code reusability, and maintainability, and allows for easier integration with other systems.
Thanks for reading this article. For more useful content like this follow my blog & share it with your friends. Comments are welcome to improve the quality of content.