Sunday, February 16, 2014

What are RESTful Web Services ?

Posted By: Achchuthan Yogarajah - 2/16/2014 04:37:00 AM

Share

& Comment

This is my first post on RESTful web service . Lets start with the basic concept of REST

What are RESTful Web Services ?

REST stands for Representational State Transfer . Its a key idiom that embraces a stateless client-server architecture in which the web services are viewed as resources and can be identified by their URLs. REST was first described by Roy Fielding in the year 2000.


RESTful webservices are based on the concept of REST and exposes a set of resources that are identified by URLs .

Wikipedia Says : REST is an architectural style consisting of a coordinated set of constraints applied to components, connectors, and data elements, within a distributed hypermedia system.

REST ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements .

HTTP Methods

GET , POST , PUT , DELETE are the common http methods that are used with the web services .

Constraints

The REST architecture applies specific interaction constraints on components , connectors and data elements. In order for an architecture to be a REST architecture, it must satisfy all of these constraints.

1. Client–Server
The first constraint is the Client-Server constraint and it is based on the principle of separation of concern . It states that the client and Server should have a uniform interface between them . This provides the flexibility to change them independently ( As long as the interface between them is not altered ).

2. Layered System
Similar to the client-server constraint, this constraint improves simplicity by separating concerns. A client and server may have multiple intermediary layers between them . This can be used to increase the scalability of the architecture as the intermediary layers can be used load balancing , or providing shared caches.

3. Stateless Communication
This constraint states that every request should contain all the information that is required to interpret that request. This increases the visibility, reliability, scalability, but also decreases performance because of the larger messages required for stateless communication.

4. Caching Constraint
There must be a mechanish such that the Resonses can define themselves as cacheable or non-cacheable . Well managed caching improves the scalability and performance .

5. Code on Demand
Code on demand is the only optional constraint of the REST architecture. This constraint extends the functionality of the client by transferring the executable code. Example Java applets.

6. Uniform Interface
The Uniform interface simplifies and decouples the architecture . The Uniform interface is fundamental to design of any REST based architecture.

6.a. Identification of resources
Resources are identified using the URIs in a web-based REST architecture.
Individual resources are identified in requests, for example using URIs in web-based REST systems. The resources themselves are conceptually separate from the representations that are returned to the client.

6.b. Manipulation of resources through these representations
The representation of a resource (including any metadata ) has enough enformation and can be used by the client to modify the resourse on the server.

6.c. Self-descriptive messages
The messages must include metadata which describe the meaning of the message. The metadata helps in identifying how to process the message.
Responses also explicitly indicate their cacheability.

6.d. Hypermedia Constraint
The steps in a REST architecture must be invoked through hypermedia.
Applications conforming to the above constraints can be considerd as RESTful. If a service violates any of the required constraints , it cannot be considered RESTful .


When should we use REST ?

A RESTful design may be appropriate when :
  • The web services are completely stateless .
  • When bandwidth is important and is limited . 
  • REST is useful for limited profile devices such as mobiles and PDAs.
  • When caching mechanism can be leveraged for enhancing the performance .For example for the responses that are not dynamic can be cached to increase the performance.

About Achchuthan Yogarajah

I’m passionate about Web Development and Programming and I go to extreme efforts to meet my passion. I’m a believer of learning the fundamentals first. I try to understand everything little bit more than the average.

Copyright © 2016 Believe in Yourself - Achchuthan Yogarajah ACHCHUTHAN.ORG. Designed by Templateism .