REST- REpresentational State Transfer

WCF
WCF @Image courtesy of ddpavumba/ FreeDigitalPhotos.net

REST- REpresentational State Transfer

Welcome to CodeSpread!

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.

request-response

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.

HTTP verbs

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.

http://localhost/ForeCastService/forecast/day/1.

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.

http://localhost/ForeCastService/updateforecast

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.

http://localhost/ForeCastService/createresource

DELETE – The DELETE method is used to delete a specific resource.

http://localhost/ForeCastService/deleteresource/1234

Now, We have some idea about REST services. We will dive deep into REST implementations in subsequent articles. Please send your feedback to admin@codespread.com

Author: hershey

A passion for knowledge drives me to do programming, A passion for programming drives me to create something different, A passion for creation drives me to spread the knowledge.

Share This Post On

0 Comments

  1. nice superb explaination

    Post a Reply
  2. thanks for the tutorial
    I am having a problem.
    The feature “Create SQL server database” isn’t available , I can’t select it.
    Can you help, please ?

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

More from CodeSpread:

  • Few lines about WCF metadataFew lines about WCF metadataWhat is WCF metadata? WCF generates metadata for service endpoints and this metadata is used to describe how to interact with the service's endpoints. This information is used by Svcutil.exe to ge...
  • WCF Part 1: Why WCF?WCF Part 1: Why WCF?When i create a WCF service, i feel like it is a very easy task but when somebody asks me, why you have created it? then the simplest answer is, i got the requirement like this. But to be honest, N...
  • WCF Part 2: Fundamentals.WCF Part 2: Fundamentals.We have seen the evolution of WCF in our previous article: WCF Part 1: Why WCF?. Next, we will go through the fundamentals of WCF. I will try to make it more worthy than an interview question puff....
  • Caching in WCF ServicesCaching in WCF ServicesYes, It is possible and clearly a  significant performance enhancement. How caching works for WCF services? Lets assume, a user sends a request to a service so at server, service method is called...
  • Difference Between Transport and Message Security in WCFDifference Between Transport and Message Security in WCFTransport Security in WCF As the name suggests, it is concerned with security of communication between client and the service over a network protocol. It guarantees the confidentiality and integri...
  • WCF Part 3: Direct from WCF kitchen.WCF Part 3: Direct from WCF kitchen.In the last two articles WCF:Part 1 and WCF Part 2, we have covered basic knowledge and terminologies of WCF.Now we will apply that knowledge to create a WCF service.There are lot of articles avail...
  • Agile Encounters UnpredictabilityAgile Encounters UnpredictabilityWhat is Agile? Wikipedia says “Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through...
  • 19 Dec: Must Read Codes [1-5]19 Dec: Must Read Codes [1-5]We are sharing few must read codes/concepts which are required now and then. Each of these codereads doesn't require a full length descriptive article so combining them into groups of five. CodeRe...