title: Using HATEOAS and Backbone.js
body: <p>I've started experimenting with Backbone.js, and was struck by the documentation for the documentation for the <a href="http://documentcloud.github.com/backbone/#Model-url" rel="noreferrer">url</a> property on Backbone.Model.</p>
  
  <p>In particular, I'm building out a REST API that uses HATEOAS/hypermedia to drive the client(s).</p>
  
  <p>I can see the usefulness of Backbone's default behaviour of building up URLs itself for items in a collection, but for my case, would prefer to have the model URLs built out of the data that is parsed.</p>
  
  <p>Has anyone extended/built on Backbone to make it do this? Maybe building upon a "standard" like <a href="http://stateless.co/hal_specification.html" rel="noreferrer">HAL</a>?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>For clarification, let's say I have the following:</p>
  
  <p>GET /orders >></p>
  
  <pre><code>[
    {
       "_links": {
         "self": "/orders/123"
       }
       "name": "Order #123",
       "date": "2012/02/23"
    },
    {
       "_links": {
         "self": "/orders/6666"
       }
       "name": "Order #666",
       "date": "2012/03/01"
    },
  ]
  </code></pre>
  
  <p>and I have an Order model like:</p>
  
  <pre><code>var Order = Backbone.Model.extend({
  });
  </code></pre>
  
  <p>I would like the <code>url</code> property to be automatically pulled out of the "self" reference in the HAL. I think creating a new base model something like (not tested):</p>
  
  <pre><code>var HalModel = Backbone.Model.extend({
    url: function() {
      return get("_links").self;
    },
  });
  </code></pre>
  
  <p>Thoughts?</p>