A RESTful style is appropriate when
- The web services are completely stateless. Each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.
- A caching infrastructure can be leverage for performance. A message sent using RESTful Web Services can be cached in the intermediaries, such as proxy servers, cache servers, gateways, etc, between the client and the Server to give high performance, so next time when the client request for the same data, data stored at the cache should be sent to the client.e.g Google Maps is using RESTful uris to provide cachable map tiles.
- The bandwidth needs to be limited. Since, there is no overhead of headers in the REST messages (unlike SOAP messages), REST messages would not need that high bandwidth as is required in case of SOAP Web Services. So, RESTful Web Services can be very useful for limited-profile devices such as PDAs and mobile phones.
- RESTful Web Services can be consumed very easily by the clients. e.g using AJAX, Clients can consume RESTful Web Services directly on their Web pages with simplicity. Rather than starting from scratch, services can be exposed with XML and consumed by HTML pages without significantly refactoring the existing web site architecture. So, existing developers will be more productive because they are adding to something they are already familiar with, rather than having to start from scratch with new technology.
- I have always found, development with REST is easier and quicker than SOAP. Because, of this most of the vendors are adopting RESTful Web Services e.g Flickr, Google etc.
- RESTful Web Services supports a variety of data formats e.g HTML, XML, plain text, PDF, JPEG, JSON etc. RESTful interfaces can easily support different content-types/mime-types.
REST is an architectural style which was brought in by Roy Fielding in 2000 in his doctoral thesis. Any software, technology adhering with the defination of REST would be considered as REST based. So, in the context of Web Services, RESTful Web Services are the one which supports REST concept.
What are RESTFull Web Services:
RESTFull Web Services refers to a stateless client-server architecture in which the Web Services (data, functionality on server side) are considered as resources and can be accessed using their uniform Resource Identifiers (URI’s).
The response from server is considered as the representation of the resources. This representation can be generated from one resource or more number of resources.
So, in RESTful Web Services, Server is viewed as a set of resources and can be accessed using Uniform Resource Identifiers (URIs).
In the REST architectural style, clients and servers exchange representations of resources by using a standardized interface and protocol. HTTP protocol best describes REST, so all the existing vendors are supporting RESTfull Web Services using HTTP protocol. But, as such any other protocol can be used to realize RESTfull Web Services as long as it adheres with the REST principles.
A resource can be any coherent and meaningful concept that may be addressed e.g an entry of student record in the database with roll number (23) as a primary key etc. A representation of a resource is typically a document that captures the current or intended state of a resource e.g HTML page, PDF etc.
But, only thing to be noted is, this resource must be having a unique URI (like
https://www.school.com/studentRecord/rollnum=23), which a client would use to access it.
Following are the features of RESTful Web Services:
- Client directly access a Resource using its URI: Resources are identified by their URIs (typically links on internet). So, a client can directly access a RESTful Web Services using the URIs of the resources (same as you put a website address in the browser’s address bar and get some representation as response).
- Uniform interface: Resources on the server can be manipulated by a client using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE. PUT creates a new resource, which can be then deleted by using DELETE. GET retrieves the current state of a resource in some representation. POST transfers a new state onto a resource.
- Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others. Metadata about the resource is available and used, for example, to control caching, detect transmission errors, negotiate the appropriate representation format, and perform authentication or access control. Every such information will be available in the message itself.
RESTful applications are simple, lightweight and fast. Developers can expect a lot of performance and scalability enhancements. But, still there are many other factors which a developer needs to analyse before he decides to go for RESTful Web Services and not any other style of Web Services e.g SOAP Web Services.
A lot of press surrounds the Web services market today. But still most of us are not aware about its importance and power. In this post, I will teach you about why you should learn web services.
What are web services
Web Services is a way to establish communication between softwares which could be running on differnt machines (different platforms or operating systems), having been developed using differnt languages e.g java, .net, c++ etc.
e.g let’s say you are a java developer. then using java web services you can publish your application’s functions to other softwares on Internet or LAN or WAN. So any other software written in any language e.g .net, c++ etc on network can access functions of your java application.
But, why you should learn such a technology ??
Here is the list of some strong reasons to support web services:
Reason 1: Reusing functionality of already developed (old) systems in new softwares.
Let’s say you are developing a Software – “weather forecasting analyzer” using java and in this software you would need to get weather report of a particular date apart from other complex calculations.
You have got one old softwrae written using .net technologies which performs the above task i.e if you pass date to one of its functions, it will return the weather report of that day.
Now, my question to you is: would you really like to write the same code again in the new software or you would like to learn a technology which will allow your new software to call a function written in old .net software ?
I belive you would definately support the idea of resuability.
Reason 2: Web Services – A cross-platform, cross-language data model, facilitates the development of heterogeneous distributed applications.
Heterogenous distributed application means – different softwares develped using different languages, platforms, operating sytems and running on different machines with varied geographic locations but can communicate through a compter network developed for a common goal.
Reason 3: Accessibility of applications through firewalls using Web protocols again sounds a very good reason as in the earlier technologies for interoperability like DCOM, CORBA etc, firewalls posed a serious blocker.
Application’s interoperability is the goal of web services and Because you access and develop Web services using standard Web protocols such as XML and HTTP, the diverse and heterogeneous applications on the Web (which typically already understand XML and HTTP) can automatically access Web services and communicate with each other.