API stands for application programming interface, which is a set of definitions and protocols for building and integrating application software. APIs let your product or service communicate with other products and services without having to know how they’re implemented.
REST API stands for Representational State Transfer Rest API which is industry known and used. REST API lets the a web app or web page communicate with cloud-servers
.
REST API is all about:
Communication (Client-Server and vice versa)
RESTFUL aka Restful web service (a service that uses
REST API
to communicate)
Benefits of REST API:
Simple and Standardized
You don't have to worry about how to format your data or how to format your request each time. It's standardized and easy to use.
Scalable and Stateless
As your service grows in complexity, you can easily make modifications. Stateless means you don't have to worry about which data is in which state and keep track of that across client and server.
High performance
Due to
cache
, it has high performance. As your service gets more complex, the performance stays very high.
Let us take an example and try to understand REST API better:
You own an ice cream shop and you have a webpage for your business. Someone typed through the following address in his browser:
https://icecream.com/API/flavors
Here API
signifies the API portion of the endpoint and flavors
is called the resource. This shows that we're working with flavors resource in the rest API.
In our example the main building block of the rest API are:
The request that is sent from the client to the server.
The response that is received back from the server.
When communicating with a client-server, you might want to create, read, update, and delete (CRUD). On a rest API, the equivalent of those are actually HTTP methods
.
I. CREATE <---> POST
II. READ <---> GET
III. UPDATE <---> PUT
IV. DELETE <---> DELETE
If you want to get the flavors of ice cream available - GET request.
If some ice-cream flavor due to high demand gets all sold and you want to update that on the web page - PUT request.
If some ice cream flavor is not available, then you can remove the flavour from the web page - DELETE request.
Great! So, hopefully, this clarifies what exactly is REST API. What are some of the benefits? What a real-world example looks like.