Home / Articles / Programming Languages / Web Services / A Web Services Primer (9/10): Until We REST!

“Chishiki” is Japanese for “knowledge.” e-chishiki.com aims to bring software developers, information security professionals, IT executives and other IT pros a rich body of knowledge in the form of articles, interviews, tutorials and technical discussions. Our contributors are among the biggest names in the Indian IT industry and include noted authors, educators and practitioners.

Weekly Programming Series - A Web Services Primer

A Web Services Primer (9/10): Until We REST!

Yashavant Kanetkar and Asang Dani
Yashavant Kanetkar and Asang Dani

Index

  1. Representational State Transfer (REST)
  2. REST Mechanisms In ASP.NET
Freedom to use an architecture of choice has always been a dream for distributed service developers. Although SOAP based XML services have become quite popular among a wide range of programmers, simplicity and uniformity in implementation of these standards is certainly not the case even today. Making use of Web Services developed in .NET through Java, PHP or JavaScript still remains a significant challenge. Over the years another model for creating and using Web Services has firmly taken root in the realm of almost every popular Web Services platform today – REST. In this article we will show you how to modify our CurrencyService implementation to support SOAP and REST approaches simultaneously in a perfectly harmonious manner.

Representational State Transfer (REST)

REST has its origins in a PhD thesis submitted by Roy Fielding – one of the principal authors of the HTTP specification. He proposed a new architectural style of programming in a distributed environment using an elegant and simple approach which relies on two fundamental principles:

  • Represent/map the functionality of a Web Service using a URL scheme.
  • Implement the APIs using standard HTTP methods, viz: GET, POST, LIST, PUT, DELETE etc.

To make things more concrete, consider the CurrencyWebService implemented using a SOAP approach. It implements the following APIs:

Function

Description

CountryCurrencyGetCurrency
( String cname )
Returns the currency details for specified country
float GetRateByCountry
( String from, String to )
Returns the latest rate of conversion from one country's currency to another
float GetRateBySymbol ( String from, String to ) Returns the latest rate of conversion from one currency symbol to another
String [ ] GetCountryNames( ) Returns an array of country names
CountryCurrency [ ]
GetCountryCurrencies( )
Returns an array containing names of all countries along with their currency names and symbols
Table 1: SOAP based Web Service Model

In the SOAP based approach, WSDL is used to convey signature of APIs and associated types (e.g. CountryCurrency). If we follow the REST based approach, the URLs to represent corresponding APIs would be as shown in Table 2.

URL

Description

http://localhost/CurrencyService/
country/India
GET http request on this URL will return the currency information for a country (India in our case).
http://localhost/CurrencyService/
country/India/Japan
GET http request on this URL will return the latest conversion rate from Indian Rupees to Japanese Yen using country name as parameter.
http://localhost/CurrencyService/
country/INR/JPY
GET http request on this URL will return conversion rate from Indian Rupees to Japanese Yen using respective currency symbols as parameters.
http://localhost/CurrencyService/
country
LIST http request on this URL will return the list of country names.
http://localhost/CurrencyService/
symbol/
LIST http request on this URL will return the list of countries, currency names and symbols.
Table 2: REST based Web Service Model

As you can clearly see, the REST model captures the essence of APIs in URLs and standard HTTP operations like GET, LIST, PUT, DELETE on these URLs. This simplicity is what makes REST so appealing. While SOAP is standards based REST offers freedom to the clients of a Web Service. REST truly captures the essence of HTTP "resources" in URLs (or nouns) and operations (or verbs) on those resources. In the next section, we will show you how to extend the existing Web Service implementation to provide REST based access to the CurrencyWebService.

Comments

Log in or create a user account to comment.

On Sale From April 2008

Let Us C
8th Ed.
C programming classic & best seller. 1 million+ copies sold!

Y. Kanetkar

On Sale From April 2008

Introduction to Object Oriented Programming & C++

Y. Kanetkar

On Sale From Fall 2008

Microsoft .NET Framework: Web Application Security

Vijay Mukhi

On Sale From Nolvember 2008

Quest C++ Courseware
12+ hours of instructional audio and animated slides.

Y. Kanetkar Asang Dani

On Sale From November 2008

A Programmer's Guide to Web Application Security

Vijay Mukhi

Latest Forum Posts