Understand WCF: Part 2: Understand RESTful Service

Welcome to the Understand WCF article series. Here we are explaining WCF from the very beginning. In our previous explanation we learned what SOA, Messages and Services are. Hope you have understood them. You can find it here:
 
 
This article will clarify a few more concepts related to services and protocols. It will help us to understand WCF better. They are very important concepts needed to be understood before starting with WCF and REST.
 

What is REST

 
The acronym REST stands for Representational STate Transfer. Let's start with the official definition of REST.
 
REST is an architectural style built with certain features on top of the traditional web.
 
We are saying that it is an architectural style. What does that mean? Architectural style is nothing but a logical concept that needs to be implemented in our own way. Say for example, the method of preparing tea is an architectural style (let's think). Now how we prepare tea depends on our own preferences. Someone likes more sugar, someone does not. Someone likes milk tea, whereas someone row. So architectural style is a concept and how it will be implemented is different.
 
The REST architectural style was developed by the W3C Technical Group (TAG) in parallel with HTTP 1.1 based on the existing design of HTTP 1.0.
 

Why REST?

 
Let's understand why REST is needed and popular, in a few words. People were trying to communicate among systems. They had invented so many methods to do it, like RPC, CORBA and so on. But the problem is that they are complex in nature and tough to implement. People started thinking to use some existing method that is already popular and easy to implement.
 
And they implemented the simple REST style over HTTP that is already famous and widely accepted.
 
The REST architectural style describes the following five constraints.
 
Uniform interface
 
The uniform interface simplifies and decouples the architecture, that enable each part to evolve independently. REST uses a few vocabularies, like GET, PUT, POST, DELETE to perform CRUD operations. Hence it maintains uniformity across any request.
 
Stateless in nature
 
REST is stateless in nature because it is built on top of HTTP, as we know HTTP is stateless and that's why REST is also stateless.
 
Cacheable
 
As on the World Wide Web, a client can cache the response.
 
Client -Server model
 
Since REST is on top of the WWW and HTTP it naturally supports client server architecture. The separation of concerns separates the client and server code.
 
Layered system
 
It supports a layered architecture. A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way. Layered architecture implements security policy.
 
OK, so we have learned those five properties of RESTful services and now we will concentrate a little on HTTP methods. As we have explained earlier in this article, REST is on top of HTTP so it supports all features of HTTP. Probably you know the meaning of GET, POST, PUT and DELETE methods of HTTP. If you are new to those terms then the following paragraph is for you.
 
Think of everything as a resource
 
Though it's recommended to not think of everything as resources in our real life, when we talk about WCF, let's reject this concept and start thinking of everything as resources.
 
RESTful applications use the following verbs to perform operations on resources:
  • GET: To get data from a server. For example when we click on an URL then we are requesting the server use the GET method. People type www.xyzabc.com in the address bar of a web browser, so they are requesting
    the web server to get this website.
  • POST: A POST operation is performed when we submit data to the server. For example when we fill up a form and press the submit button, the POST operation is performed (generally people set their form method as POST).
  • PUT: Used to create a resource, or overwrite it. You specify the resource of the new URL.
  • DELETE: To perform a delete operation. For example, we want to delete information by supplying its ID.
Those HTTP methods are now well known and when we combine those methods with a URL resource it creates a uniform interface. 
 

Conclusion

 
In this quick article, we have explained all about REST and its importance and popularity. Hope you have understood the concept. In a future article, we will start to develop a WCF application with examples.
 


Similar Articles