SOA using REST

Roy Fielding’s explanation of the meaning of Representational State Transfer (REST):

“Representational State Transfer (REST) is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.”

REST has gained widespread acceptance across the Web as a simpler alternative to SOAP and Web Services Description Language (WSDL) based Web services. REST has caught on as a way to design Web services with less dependence on proprietary middle-ware (for example, an application server).

Mainstream Web 2.0 service providers are adopting REST that is convincing evidence of this shift in interface design. Now, years after its introduction in year 2000, major frameworks for REST are available in market. For example, even it has become an integral part of Java™ 6 through JSR-311 and another example is Apache CXF.

REST – An Architectural Style, Not a Standard and here are few design considerations in implementation of a REST Web service:

  • Use HTTP methods explicitly having uniform URI: For example,

To add a new user “Tom”:

POST /users HTTP/1.1

Host: myserver

Content-Type: application/xml

<?xml version=”1.0″?> <user>   <name>Tom</name> </user>

To retrieve user “Tom”:

GET /users/Tom HTTP/1.1Host: myserverContent-Type: application/xml

To update user “Tom” with “Bob”:

PUT /users/Tom HTTP/1.1

Host: myserver

Content-Type: application/xml

<?xml version=”1.0″?> <user>   <name>Bob</name> </user>

Another example:

Request Operation
PUT http://MyService/Persons/ Won’t work. PUT requires a complete URI
PUT http://MyService/Persons/1 Insert a new person with PersonID=1 if it does not already exist, or else update the existing resource
POST http://MyService/Persons/ Insert a new person every time this request is made and generate a new PersonID
POST http://MyService/Persons/1 Update the existing person where PersonID=1
  • Be stateless:

For example, in a multi page display application page number and state information should not be maintained at server side. Instead client should request the appropriate page and server would query and return that specific page data.

  • Transfer XML, JavaScript Object Notation (JSON), or both.

 

Implementing RESTful Services:

XML over HTTP is a powerful interface that allows internal applications, such as Asynchronous JavaScript + XML (Ajax)-based custom user interfaces, to easily connect, address, and consume resources. In fact, the great fit between Ajax and REST has increased the amount of attention REST is getting these days.

Exposing a system’s resources through a RESTful API is a flexible way to provide different kinds of applications with data formatted in a standard way (XML/JSON). It helps to meet integration requirements that are critical to building systems where data can be easily combined and extended or build on a set of base RESTful services into something much bigger.

A RESTful service can be easily implemented using any of the existing technologies such as Python, .NET, or Java.

The Restlet project (http://www.restlet.org) provides a lightweight, comprehensive, and reliable framework to implement any kind of RESTful system, not just RESTful web services in Java.

Leave a Reply

Your email address will not be published. Required fields are marked *

Skip to toolbar