REST- REpresentational State Transfer
REST – REpresentational State Transfer, is an enhanced version of client server style architecture for distributed communication.
When we talk about distributed communication, we think of request and response.
A request is something which is made by client to a server and in reply, response is sent back by the server to the client. What’s new in this? Nothing!!
REST brings the ‘new’ thing. This ‘new‘ thing is ‘transfer of representations of resources ‘
There are three main keywords ‘transfer’, ‘representations’ and ‘resources’. We already know the meaning of ‘transfer’ as we are talking about distributed communication. A ‘resource’ can be any object on server like a document, an image, flash etc. When client request a resource, it receives a ‘representation’ of that resource. A ‘representation’ is the current state of the resource.
How is REST an enhancement over WCF/Webservices?
For more info on WCF, refer this link, we will take an example to understand the enhancement more clearly. Suppose we have a service which maintains data of weather forecast and at client side, a proxy of this service is created where client will consume this service through the proxy by calling a method like GetTodayForecast() which will send today’s forecast data from server to client.
REST came out with noun based approach where the same method is called but with the help of URI which is referred to as noun-based approach.
This URI might look like https://localhost/TodaysForecast
Latter part of this URL ‘TodaysForecast’ is the resource in which the client is interested. This will play the role of representation of an object ‘forecast’.
The best part which I personally like is in REST, there is NO need of creating a proxy. We just need to wrap the request with HTTP verbs – GET, PUT, POST, and DELETE and the response can be an XML or JSON.
We will go through these HTTP verbs also to get more insights.
GET – GET request as the name implies will request the server for a particular resource. For example:-We might need to have forecast details of some particular day.
This HTTP request will be received by server and GetTodayForecast() method will get executed. In response, client will receive a XML or JSON response as configured.
POST – The POST method is used to create a new resource or update the existing one.
Client will send this request with an updated object ‘forecast’ to server. In response, server will send a response notification like success or fail.
PUT – We always get confuse between POST and PUT as both behave the identical way then what is the difference? The difference lies in the conditions they are performed or required to perform. If we are sending a command to create a resource through POST then there are chances that server will create as many identical resources as many times the same request it will receive.
But in PUT, server will create only one resource for the same request irrespective of the number of request it receives.
DELETE – The DELETE method is used to delete a specific resource.
Now, We have some idea about REST services. We will dive deep into REST implementations in subsequent articles. Please send your feedback to firstname.lastname@example.org