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.
2. Advantages of RESTful Web Services
There are a few main advantages to using RESTful Web Services such as –
- RESTful Web Services are fast basically because there are no strict specifications as in SOAP.
- RESTful Web Services can be written in any programming language and can be independently executed on any platform.
- 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 –
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.