Introduction to RESTFul Web Service

1. Introduction

We already understand what a Web Service is, and we have already been through a nice introduction to SOAP web services. In this article, we will understand another type of web service, which is RESTful Web Service, where REST stands for Representational State Transfer.

In a RESTful Web Service, the client application consumes the data primarily through URL parameters and Path Variables. The response from RESTful Web Services is usually a standardized XML or more popularly a JSON.

2. Advantages of RESTful Web Services

There are a few main advantages to using RESTful Web Services such as –

  1. RESTful Web Services are fast basically because there are no strict specifications as in SOAP.
  2. RESTful Web Services can be written in any programming language and can be independently executed on any platform.
  3. RESTful Web Services are flexible with the output message format, which can be Plain Text, HTML, XML or a JSON, which in case of SOAP is always an XML.

3. Further explanation with an example

When we are concerned with RESTful Web Services, the producer exposes a specific URI that should be able to fetch the needed resource for the individual consumers based on the HTTP request parameters and path variables available, based on what we have defined in our RESTful Web Service contract.


For example, consider the RESTful Web Service provided by Accuweather, which exposes a URI format like –

http://www.accuweather.com/en/us/state-college-pa/16801/current-weather/335315?lang=en-us&partner=1234

Note that the texts above in red can be retrieved as Path Variables in the Spring MVC controller, whereas lang, partner are the URL parameters that can be retrieved as Request Params in the Spring MVC controller.

Assume that I have sidebar widget on my website, and I want to display the current weather condition at the visitor’s location, I will asynchronously make a call to the above RESTful Web Service URI with appropriate Path Variables and URL parameters, which probably will return me the real time data based on the current weather conditions in, say, JSON format. I will parse the JSON response data that is returned by the RESTful Web Service, and would better choose to display this JSON data in a more presentable format probably by using core Javascript or more elegantly using some third party Javascript framework/libraries. I hope we are pretty much clear on this.

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.