The architectural style of REST makes it useful to minimise the use of bandwidth which makes an application more appropriate for the internet. It is completely based on resources and it is termed as the 'language of the internet'. REST API are stateless.
Why should we use REST API?
Consider an example where you open the Book My Show app. The application required a lot of input data, as the response is never static and it gives the response based on the data provided. It always shows or updates the movies that is getting released or various cities showing different types of cities showing different languages movies at different times of the day. The application is never static and some or the other data is getting updated.
Now, where do the app get this data from?
Well, this data is received from a Server which is known as the Web-Server. The client requests the data from a particular API and then the data is sent from them as a response.
Resources and REST
Understanding resources is more important to work with REST. To get a better understanding about what a resource is and how it can be represented using APIs, let’s consider my own personal Facebook presence, where I am a resource. I can easily view an HTML representation of my resource by accessing below URL:
My profile is one single resource which is available on facebook. By using the above URL in browser, an HTML view can be easily seen. It is also possible to it using the Facebook Graph API.
To access the API, a token is a must to access the information. But when the request is made to this resource within the Facebook Graph API, JSON data is recieved, this data can be used for further process. There are different endpoints for interacting with and the developer gets the access & can consume the resources.
Comments: GET https://graph.facebook.com/v7.0/comments
Friends: GET https://graph.facebook.com/v7.0/friends
Images: GET https://graph.facebook.com/v7.0/images
Links: GET https://graph.facebook.com/v7.0/links
Likes: GET https://graph.facebook.com/v7.0/likes
Location: GET https://graph.facebook.com/v7.0/locations
Messages: GET https://graph.facebook.com/v7.0/messages
Notifications: GET https://graph.facebook.com/v7.0/notifications
Pages: GET https://graph.facebook.com/v7.0/pages
Payments: GET https://graph.facebook.com/v7.0/payments
The Naming, organizing, and making digital resources are the main use of REST. Now,as the resources are well-defined, you can GET these resources. More importantly, it is also possible to manage the state of every single resource over time making different operations on it viz creating a new one, updating or deleting the already exisiting ones. There are different HTTP methods for the same which are listed below:
The four methods that are listed above allows us to get info, add, update, and delete the resources that is images on Facebook respectively. Facebook uses REST to allow developers to manage the state of image resources using simple URLs, HTTP, it helps in data access and provides an easy way to do so.
Overall, REST APIs are flexible and more used than SOAP API, reading the documentation to interact with REST is helpful. There are major differences between REST API's of different websites, but they all share the common patterns that is mentioned above. REST API is basically a request and response that is transmitted over the web.