title: API request from front-end using sails.io.js
body: <p>I have a basic front-end (html, css, jquery) and I'd like to use sails.io.js to communicate with an API server (developped with sails, with cors enabled). The API is running on localhost:10000 but it will be on an another domain than the one of the webclient later on.</p>
  
  <p>Directly from jquery, I can issue some get request to this API and get the expected results.  </p>
  
  <p>When it comes to websocket, I have some problems...
  In the index.html (just to test), I put the following:</p>
  
  <pre><code>&lt;script src="js/sails.io.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      io.sails.url('http://localhost:10000');
      io.socket.get('/data', function serverResponded (body, sailsResponseObject) {
        // body === sailsResponseObject.body
        console.log('Sails responded with: ', body);
        console.log('with headers: ', sailsResponseObject.headers);
        console.log('and with status code: ', sailsResponseObject.statusCode);
      });
   &lt;/script&gt;
  </code></pre>
  
  <p>But Chrome's developer tools tell me</p>
  
  <pre><code>ReferenceError: io is not defined 
  </code></pre>
  
  <p>Any idea ?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I'm serving index.html with a web server (python -m SimpleHTTPServer)<br>
  I've installed sails.io.js using bower.  </p>
  
  <p>I've try to make this test as simple as possible:</p>
  
  <p>index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;script src="bower_components/sails.io.js/dist/sails.io.js"&gt;&lt;/script&gt;
      &lt;script src="index.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>index.js:</p>
  
  <pre><code>window.onload=function(){
      io.sails.url = 'http://localhost:10000';
      io.socket.get('http://localhost:10000/data', function (body, response) {
        console.log('Sails responded with: ', body);
      });
  };
  </code></pre>
  
  <p>My sails (0.9.16) API is only returning a json object on the GET /data route.</p>
  
  <p>I have implemented a dummy __getcookie function in the api:</p>
  
  <pre><code>'get /__getcookie': function(req, res, next){
      res.json({ok: 123});
  }
  </code></pre>
  
  <p>And commented the line 481 in interpret.js (Scott comments below).</p>
  
  <p>I have also modify config/socket.js with:</p>
  
  <pre><code> authorization: false,
  </code></pre>
  
  <p>=> I can now get the result from the /data route of my API :)</p>
  
  <p>But... on each request I have the following error:</p>
  
  <pre><code>error: Error: No valid session available from this socket.
  </code></pre>