title: create models in expressjs
body: <p>I have an express app that gets its data from an external API</p>
  
  <pre><code>api.com/companies (GET, POST)
  api.com/companies/id (GET, PUT)
  </code></pre>
  
  <p>I want to create a model to make the code easier to maintain as you can see I´m repeating a lot of code here.</p>
  
  <pre><code>router.get('/companies', function(req, res, next) {
  
      http.get({
          host: 'http://api.com',
          path: '/companies'
      }, function(response) {
          var body = '';
          response.on('data', function(d) {
              body += d;
          });
      });
  
      res.render('companies', {data: body});
  });
  
  router.get('/companies/:id', function(req, res, next) {
  
      http.get({
          host: 'http://api.com',
          path: '/companies/' + req.params.id
      }, function(response) {
          var body = '';
          response.on('data', function(d) {
              body += d;
          });
      });
  
      res.render('company', {data: body});
  });
  </code></pre>
  
  <p>How can I do that?</p>