title: Setting up a RESTful backend mock with Sinon.js for an Angular.js application
body: <p>I'm developing an Angular.js application that has RESTful services which extend the $resource service. This app will connect to a Java Spring application in the future, but right now I'm trying to set up an isolated mock that will serve all the necessary routes for my application from <strong>client side</strong>. I've used Sinon.js before to create a fake client side <em>server</em> that serves my routes when I developed other apps, using other MV* frameworks, such as Backbone.js.</p>
  
  <p>It appears that unlike a "standard" ajax call for fetching JSON data, as JQuery/Backbone performs, Angular uses XHR differently, and it isn't "fooled" by Sinon's attempts of hijacking the request and responding from client side.</p>
  
  <p>I tried to use $httpBackend to create fake routes with ready data, instead, but it appears this service was meant to be used only for unit testing, and not for the "staging environment" which I need to set up.</p>
  
  <p>This is how my Sinon setup looks like, which works on JQuery.ajax, but not on Angular $resource, or $http:</p>
  
  <pre><code>var server = sinon.fakeServer.create();
  server.respondWith("GET", /mydata/gi, [200,
      { "Content-Type": "application/json" },
      JSON.stringify({
          data: "myData"
      })
  ]);
  server.autoRespond = true;
  </code></pre>
  
  <p>Any ideas to how this doesn't work with Angular? Or better yet, does anyone know how set such mocks for Angular apps?</p>