Node.js add get route - building a restful api


SUBMITTED BY: Guest

DATE: Aug. 4, 2013, 5:48 p.m.

FORMAT: Text only

SIZE: 263 Bytes

HITS: 1116

  1. app.get('/quote/:id', function(req, res) {
  2. if(quotes.length <= req.params.id || req.params.id < 0) {
  3. res.statusCode = 404;
  4. return res.send('Error 404: No quote found');
  5. }
  6. var q = quotes[req.params.id];
  7. res.json(q);
  8. });

comments powered by Disqus