Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Hierarchical REST URI support?

    I've gone through the docs, examples and forums, but haven't found something that addresses this.

    When using a RestDataSource, is there any support for a hierarchical URI?

    For example, a REST URI for a list of all employees might be http://myserver/employees. The REST URI for the details of a specific employee might be http://myserver/employees/{id} where {id} is the ID of the employee. Similarly, to update an employee's record, we would POST or PUT to http://myserver/employees/{id} with the payload being the actual data to change.

    This is a very common approach to REST interfaces but I haven't seen how to accomplish this in SmartClient without implementing a custom transformRequest. Is this how we are supposed to implement this standard URI format or have I overlooked something? Does SC provide support for a parameterized hierarchical REST URI?

    Thanks in advance,

    Solstice
    Last edited by solstice; 10 May 2011, 06:39.

    #2
    Guess I'll answer my own question: yes, it has to be done through transformRequest.

    Comment


      #3
      You are correct. If the W3C URI group ever finishes the URI template spec it will likely be incorporated.

      Comment


        #4
        In the meantime, if anyone is interested, here is how it's done.

        Place the following code in a DataSource. I recommend creating a new class.

        Code:
           transformRequest : function(dsRequest) {
              // map form values to parameterized URL
              var url = this.dataURL;
              var params = url.match(/\{([^\}]+)\}/g); 
              for(var i = 0; i < params.length; i++) {
                 var p = params[i].substring(1, params[i].length-1);
                 if(dsRequest.data[p] != null)
                    url = url.replace(params[i], dsRequest.data[p]);
              }
              dsRequest.actionURL = url;    
           
              return this.Super('transformRequest', arguments);
           }

        Comment

        Working...
        X