A brief introduction to REST APIs
What is an API?
API stands for Application Programming Interface. Simply put, it can be defined as a communication medium between the client and the server. It delivers the request by the client to the service provider and then delivers the response from the service provider back to the client.
For example, the weather bureau's software system contains daily weather data. The weather app on your phone “talks” to this system via APIs and shows you daily weather updates on your phone.
When you search for directions on Google Maps, have you ever noticed that there is an option to book a ride from different ride services?
Google Maps uses Uber’s API to request information by sending an HTTP request function with the start and end points of the ride.
Uber’s API then sends information back such as how many cars are available, where are they currently located, and the costs for the various ride options.
This information is then processed by Google Maps and is available to the user directly linking them the Uber app if it is previously downloaded.
APIs connect the world like never before. They remove previous barriers with just a few taps or clicks and can easily be integrated. Just think of them as waiters going back and forth between delivering data and creating interconnectivity.
What is REST?
REST-Representational State Transfer
It is an API that conforms to the constraints of the REST architectural style.
Principles of REST API
There are six ground principles laid down by Dr Fielding who was the one to define the REST API design in 2000. Below are the six guiding principles of REST:
Stateless
The requests sent from a client to a server will contain all the required information to make the server understand the requests sent from the client. This can be either a part of the URL, query-string parameters, body, or even headers.
Client-Server
To obtain uniformity throughout the application, REST has the following four interface constraints:
Resource identification
Resource Manipulation using representations
Self-descriptive messages
Hypermedia as the engine of application state
Cacheable
To provide a better performance, the applications are often made cacheable. This is done by labelling the response from the server as cacheable or non-cacheable either implicitly or explicitly. If the response is defined as cacheable, then the client cache can reuse the response data for equivalent responses in the future.
Layered System
The layered system architecture allows an application to be more stable by limiting component behaviour. This type of architecture helps in enhancing the application’s security as components in each layer cannot interact beyond the next immediate layer they are in. Also, it enables load balancing and provides shared caches for promoting scalability.
Code on Demand
This is an optional constraint and is used the least. It permits a client's code or applets to be downloaded and to be used within the application. In essence, it simplifies the clients by creating a smart application that does not rely on its code structure.
Now that we know the basics of REST APIs, let's look into some methods of REST APIs.
Methods of REST API
With most of us working with web technologies, we all are aware of the acronym "CRUD".
C-Create R-Read U-Update D-Delete