Saturday, September 24, 2011

RESTful Webservice

RESTful Webservice:

What is REST?
REST is a term coined by Roy Fielding in his Ph.D. dissertation to describe an architecture style of networked systems. REST is an acronym standing for Representational State Transfer. Here is Roy Fielding's explanation of the meaning of Representational State Transfer:

"Representational State Transfer 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."

What is RESTful webservice?
REST is not a standard. Its just an architectural style. While REST is not a standard, it does use standards:

. HTTP
. URL
. XML/HTML/GIF/JPEG/etc (Resource Representations)
. text/xml, text/html, image/gif, image/jpeg, etc (MIME Types)

REST Web Services Characteristics:

Client-Server: a pull-based interaction style: consuming components pull representations.
Stateless: each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.
Cache: to improve network efficiency responses must be capable of being labeled as cacheable or non-cacheable.
Uniform interface: all resources are accessed with a generic interface (e.g., HTTP GET, POST, PUT, DELETE).
Named resources: the system is comprised of resources which are named using a URL.
Interconnected resource representations: the representations of the resources are interconnected using URLs, thereby enabling a client to progress from one state to another.
Layered components: intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients and resources to support performance, security, etc.

Principles of REST Web Service Design
  • The key to creating Web Services in a REST network (i.e., the Web) is to identify all of the conceptual entities that you wish to expose as services. Above we saw some examples of resources: parts list, detailed part data, purchase order.
  • Create a URL to each resource. The resources should be nouns, not verbs. For example, do not use this:
               http://www.parts-depot.com/parts/getPart?id=00345
               Note the verb, getPart. Instead, use a noun:
               http://www.parts-depot.com/parts/00345
  • Categorize your resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE.
  • All resources accessible via HTTP GET should be side-effect free. That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource.
  • No man/woman is an island. Likewise, no representation should be an island. In other words, put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information.
  • Design to reveal data gradually. Don't reveal everything in a single response document. Provide hyperlinks to obtain more details.
  • Specify the format of response data using a schema (DTD, W3C Schema, RelaxNG, or Schematron). For those services that require a POST or PUT to it, also provide a schema to specify the format of the response.
  • Describe how your services are to be invoked using either a WSDL document, or simply an HTML document.

No comments:

Post a Comment