REST, or Representational State Transfer, is a style of software architecture for accessing information on the Web. The RESTful service refers to web services as resources that use XML over the http protocol. The term REST dates back to 2000, when Roy Fielding used it in his doctoral dissertation.
The W3C recommends using WSDL 2.0 as the language for defining REST web services. To explain REST, let’s take an example of purchasing items from a catalog application.Defining CRUD
First we will define CRUD operations for this service as following.The term CRUD stands for basic database operations Create Read Update and Delete.
Defining XSD
As you know already, REST is based on XML, and the client and server will communicate using XML over http. We can define Item xsd as the following. attributeFormDefault="unqualified">
describing root element
How CRUD Works
To get a list of items the client can send a GET request to the server: GET http://myserver:port/catalogapp/RestService/itemIn return, the server lists the entire items in the following format confirming to item xsd.- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1
Pen http://myserver:port/catalogapp/item/1 3.14 2 Book http://myserver:port/catalogapp/item/2 3.00
Next, to get the detail of an individual item the client can send request like this:
GET http://myserver:port/catalogapp/RestService/item/1For this example we have not defined xsd for item details. For now, let's use the same item schema for detail. The server can return information about single item as following.
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1 Pen http://myserver:port/catalogapp/RestService/item/1 3.14
For creating a new item, the client can send a POST request as seen below. Here we are creating a new item with the name "Cap" and price "2.00."
POST http://myserver:port/catalogapp/RestService/item
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Pen 3.14
The above post xml for creating a new item does not have Id and Url. The reason is this: catalogapp generates an Id for every new Item. Also, the url is generated when the client executes the send read (GET) operation.
We have defined the "PUT" method for updating an item. But there are servers that do not support the PUT method, and also with HTTP servlets it is more easy to work with POST than PUT. In the operation method detail you can publish the POST method in place of PUT for the update operation. We will continue with the PUT method in this example.PUT http://myserver:port/catalogapp/RestService/item/1
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1 Pen 3.20
The price of the item is updated with the above PUT request. In case you intend to use POST for update operations, you need to decide whether the POST request is create or update operation. The catalogapp can look for tag Interface documents
How does the client know what to expect in return when it makes a call for CRUD operations? The answer is the interface document. In this document you can define the CRUD operation mapping, Item.xsd file, and request and response xml. You can have separate xsd for request and response, or response can have text such as "success" in return for the methods other than GET.Frameworks
There are other frameworks available for RESTful Services. Some of them are listed here.
- * Sun reference implementation for JAX-RS code-named Jersey. (Jersey uses a HTTP web server called Grizzly, and the Servlet Grizzly Servlet)
* Ruby on Rails
* Restlet
* Django
* Axis2a