title: Should I have different method calls for my RESTful API?
body: <p>I'm writing a web application on using Express. It has a RESTful API. The authentication schemes are different for the web interface and the RESTful API. Now I have something like this. The following code has the auth mechanisms stripped off.</p>
  
  <p><strong>problem.js</strong></p>
  
  <pre><code>// Web
  exports.list = function(req, res) {
    listProblems(function(err, problems) {
      if(err) {
        res.send(err);
      } else {
        res.render('problems', { title: 'Problems', problems: problems });
      }
    });
  };
  
  // REST API
  exports.apiList = function(req, res) {
    listProblems(function(err, problems) {
      if(err) {
        res.send(err);
      } else {
        res.json(problems);
      }
    });
  };
  
  // Named function to query MongoDB, common to both Web and REST
  function listProblems(callback) {
    var query = Problem.find().select(DEFAULT_FIELDS);
    query.exec(callback);
  };
  </code></pre>
  
  <p>Routes in <strong>app.js</strong></p>
  
  <pre><code>app.get('/problems', problem.list);
  app.get('/api/v1/problems', problem.apiList);
  </code></pre>
  
  <p>I'm not sure if I'm doing the right thing. Please let me know. Many thanks in advance.</p>