ariatemplates/ariatemplates — pull request #221 by apicolet (2012-11-08 10:36:30+00:00)
Title: URLService proposed improvements

## Change
Two changes to the `URLService` framework, needed for interaction with RESTFul services :
* now modules can pass a full `service specification` structure, instead of a raw `actionName` string, to be used by the `URLService` to determine the target request
* an `URLService` can now return a structured `request details` instead of a raw URL, which can for now contain URL and HTTP method; this mechanism could later be used for `URLService` to define needed HTTP headers as well (`Range:`, `Accept:`, ...)

## Example use

### New way to call sendJsonRequest from a module :
```javascript
this.submitJsonRequest(
{name:"fm.flightleg.get",
params:{flight:"AF226",departurePort:"CDG"}},
null,
{
fn : this._onRequest,
scope : this,
args:{}
});
},
```

### Usage in an URLService implementation :
```javascript
$actionMap: {
"fm.flightleg.get" : {
method : "GET", url: "/flight/{flight}/leg/{departurePort}"
},
"fm.flightleg.update" : {
method : "POST", url: "/flight/{flight}/leg/{departurePort}"
}
},

createServiceUrl : function (moduleName, serviceSpec, sessionId) {
var actionName = serviceSpec.name;
var actionParams = serviceSpec.params;
var actionDef = this.$actionMap[actionName];
if (!actionDef) {
return '';
}
//TODO : do a generic URL template engine
var url = actionDef.url;
url = url.replace(/\{flight\}/,actionParams.flight);
url = url.replace(/\{departurePort\}/,actionParams.departurePort);

if (sessionId) {
url = aria.modules.RequestMgr.__appendActionParameters(url,"SITK="+sessionId);
}

return {
url: this.baseUrl+url,
method: actionDef.method
};
}
```