Thursday, March 20th, 2008

SMD: Pluggable Web Services

Category: Dojo, JavaScript, JSON, Library

javascript

  1. {target:"/jsonrpc", // this defines the URL to connect for the services
  2.  transport:"POST", // We will use POST as the transport
  3.  envelope:"JSON-RPC-1.2", // We will use JSON-RPC
  4.  SMDVersion:"2.0",
  5.  services: {
  6.    add : { // define a service to add two numbers
  7.    parameters: [
  8.      {name:"a",type:"number"}, // define the two parameters
  9.      {name:"b",type:"number"}],
  10.    returns:{"type":"number"}
  11.  },
  12.  foo : {   // nothing is required to be defined, all definitions are optional.
  13.    //This service has nothing defined so it can take any parameters
  14.   //and return any value
  15.  },
  16.  getNews : {
  17.    // we can redefine the target, transport, and envelope for specific services
  18.    target: "/newsSearch",
  19.    transport: "GET",
  20.    envelope: "URL",
  21.    parameters:[ { name: "query", type: "string", optional: false, default: "" } ],
  22.    returns:{type:"array"}
  23.  }
  24. }

What is that? Does it look a little WSDL-y without the XML? This format is Service Mapping Description (SMD), and Kris Zyp talks about how it enables pluggable Web services.

With the schema about you can wire it together (example using Dojo):

javascript

  1. var services = new dojox.rpc.Service("http://mydomain.com/mySMD");
  2.  
  3. var newsDeferred = services.getNews({query:"dojo"});
  4. newsDeferred.addCallback(function(returnValue) {
  5.     alert("A news item: " + returnValue[0]);
  6. });

Neil Roberts asked about cross domain SMDs and Kris said:

Yes, we will use JSONP, although we use a special form, where the callback function will be derived directly from the name of the SMD, in order to allow for static creation of SMDs that can be accessed cross-domain.

Posted by Dion Almaer at 7:46 am
Comment here

++++-
4 rating from 26 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.