RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Integrating AJAX Clients and RESTful Web Services

The integration of AJAX clients and RESTful web services results in powerful yet straightforward service-oriented web applications.

t is no coincidence that AJAX and RESTful web services gained the attention of developers in their respective stages of infancy. Both technologies emerged during times that were dominated by cumbersome enterprise technologies. They gained popularity because of the freshness, innovation, and simplicity that they brought into the lives of hands-on technologists. AJAX brought the immediate gratification associated with a dynamic web experience, while RESTful web services brought the simplicity and pragmatism that developers expected from the web services concept but faced complex web services specifications.

Many also recognized that these two technologies offered the opportunity to create new models for service-oriented web applications. Being very compatible, AJAX and RESTful web services could be integrated and composed in new ways. These two technologies fit together particularly well for a number of reasons:

  1. Both AJAX and RESTful web services leverage widely available web technologies and standards such as HTML, JavaScript, browser objects, and HTTP. There is absolutely no need to buy, install, or configure any other major component to enable effective interaction between AJAX front ends and RESTful web services.
  2. Integration between these two technologies is simple. An AJAX front end implements a RESTful web service simply by invoking the RESTful URL with an HTTP method. If you need to pass any messages as parameters to the RESTful web service, you just issue them into the service as standard parameters of the HTTP query string like this:
    function getLastShipmentLocation( String shipmentID ){
      var URLString = "https://localhost:8080/GlobalTracking/shipments/" + shipmentID;
      //Issue AJAX request to Shipment RESTful service with last location as parameter 
      new Ajax.Request(URLString, {
                       method: 'get',
          parameters: {location: 'last', limit: 12}
  3. AJAX naturally supports an essential feature of RESTful web services: resources as URLs. With RESTful web services each entity or resource is presented as an individual URL. For example, in an online shipment-tracking service (see article for reference) a shipment that you are interested in tracking would be presented as follows:
    AJAX-enabled applications naturally construct URLs on the fly based on user input. So the method to invoke a RESTful URL to get the status on a shipment with the tracking ID 101 would look like this:
    function getShipmentLocation( String shipmentID ){
      //append shipment ID to get the status on the shipment from the service 
      var URLString = "https://localhost:8080/GlobalTracking/shipments/" + shipmentID;
      //Issue AJAX request to Shipment RESTful service to get shipment status 
      new Ajax.Request(URLString, {
                       method: 'get'}

    This example uses the Prototype framework to invoke URLs asynchronously because Prototype encapsulates and therefore simplifies logic that deals with cross-browser compatibility, asynchronous invocations of XMLHttpRequest, response codes checking, and HTTP method dispatching. However, you can opt to use XMLHttpRequest directly to issue RESTful web service calls.

  4. RESTful web services offer flexibility and freedom in your selection of message formats. Unlike SOAP web services they are not XML-only. In fact, the REST specification does not mandate using XML for RESTful web services.

My two previous articles about REST and enterprise service bus (ESB) integration reviewed the basics of RESTful web services and explored the solutions available for connecting RESTful web services to an ESB. This article discusses the third major area of interest for contemporary software developers: integrating AJAX-enabled application web front ends with backend services as RESTful web services.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date