When to and When not to use REST

Architects and developers need to decide when this particular style is an appropriate choice for their applications.

A RESTFul design may be appropriate when:
  • The web services are completely stateless. A good test is to consider whether the interaction can survive a restart of the server.
  • A caching infrastructure can be leveraged for performance. If the data that the web service returns is not dynamically generated and can be cached, then the caching infrastructure that web servers and other intermediaries inherently provide can be leveraged to improve performance. However, the developer must take care because such caches are limited to the HTTP GET method for most servers.
  • The service producer and service consumer have a mutual understanding of the context and content being passed along. Because there is no formal way to describe the web services interface, both parties must agree out of band on the schemas that describe the data being exchanged and on ways to process it meaningfully. In the real world, most commercial applications that expose services as RESTful implementations also distribute so-called value-added toolkits that describe the interfaces to developers in popular programming languages.
  • Bandwidth is particularly important and needs to be limited. REST is particularly useful for limited-profile devices such as PDAs and mobile phones, for which the overhead of headers and additional layers of SOAP elements on the XML payload must be restricted.
  • Web service delivery or aggregation into existing web sites can be enabled easily with a RESTful style. Developers can use technologies such as Asynchronous JavaScript with XML (AJAX) and toolkits such as Direct Web Remoting (DWR) to consume the services in their web applications. Rather than starting from scratch, services can be exposed with XML and consumed by HTML pages without significantly refactoring the existing web site architecture. Existing developers will be more productive because they are adding to something they are already familiar with, rather than having to start from scratch with new technology.

A SOAP-based design may be appropriate when
:

  • A formal contract must be established to describe the interface that the web service offers. The Web Services Description Language (WSDL) describes the details such as messages, operations, bindings, and location of the web service.
  • The architecture must address complex nonfunctional requirements. Many web services specifications address such requirements and establish a common vocabulary for them. Examples include Transactions, Security, Addressing, Trust, Coordination, and so on. Most real-world applications go beyond simple CRUD operations and require contextual information and conversational state to be maintained. With the RESTful approach, developers must build this plumbing into the application layer themselves.
  • The architecture needs to handle asynchronous processing and invocation. In such cases, the infrastructure provided by standards such as WSRM and APIs such as JAX-WS with their client-side asynchronous invocation support can be leveraged out of the box.

    1 comments:

    phillc said...

    "The web services are completely stateless. A good test is to consider whether the interaction can survive a restart of the server."

    A RESTful design requires it to be stateless... In the web world, this usually just means that two requests cannot share information with each other.
    Some APIs have adpoted REST-like designs... They make the requestor authenticate once, then run the desired request on the API... (That is not stateless)



    "A caching infrastructure can be leveraged for performance. If the data that the web service returns is not dynamically generated and can be cached, then the caching infrastructure that web servers and other intermediaries inherently provide can be leveraged to improve performance. However, the developer must take care because such caches are limited to the HTTP GET method for most servers."

    The beauty of a stateless system is that it scales well. Under share nothing architecture, you can have have many servers open for the API, and you do not have to worry about which server is handling the request if no information needs to be stored between different requests... so you can scale horizontally easily.

    "Web service delivery or aggregation into existing web sites can be enabled easily with a RESTful style. Developers can use technologies such as Asynchronous JavaScript with XML (AJAX) and toolkits such as Direct Web Remoting (DWR) to consume the services in their web applications. Rather than starting from scratch, services can be exposed with XML and consumed by HTML pages without significantly refactoring the existing web site architecture. Existing developers will be more productive because they are adding to something they are already familiar with, rather than having to start from scratch with new technology."

    IMHO, the most awesome thing about RESTful design is the ability to request a different content type on a per request basis.
    This is extremely awesome for those who use the MVC pattern for web development
    If you are familiar with MVC in web development, you know that requests are routed to an appropriate controller, who runs methods on a model and then sends that information to the appropriate view.
    Now, the "appropriate" view can be determined by the content type requested.
    Real example: a request to http://example.com/potatoes/1 by a web browser might take you to a webpage where it shows you some information about something. However, say I was making an AJAX based website, and wanted some information in JSON... if implemented this way, I could make a request on the exact same url with a content-type request of JSON... and get it! Maybe I want it in XML? OK! Maybe I want to create a potato? POST request to http://example.com/potatoes . Maybe I want a response that it was successful or not in XML too... just request it that way! Awesome!

    For me, however, the most important is the ability to have the same controller code act as the bulk of the work for my HTML... and then double over to be able to send JSON out if I want the same data in an AJAX call or something.

    Post a Comment