0.0.4 • Published 10 years ago

groove-js v0.0.4

Weekly downloads
2
License
BSD
Repository
github
Last release
10 years ago

Groove.js

A connect.js router for APIs.

Usage

var app = connect()
  .use(connect.logger('dev'))
  .use(connect.static('public'))
  .use(groove.route({
    'GET /ponies.json': poniesController.list
    'POST /ponies.json': poniesController.create
  }));

Why use Groove.js?

Expressiveness

When developing APIs your code is usually coupled to the HTTP method, the URL and the querystring. Groove.js let you express that coupling without bloating your handler function.

// Using Express.js
var handler = function(req, res) {
  if (! req.query['type']) {
    return res.json(find());
  }

  if (req.query['type'] === 'upcoming') {
    if (req.query['cityId']) {
      res.json(findByCity(req.query['cityId'], 'upcoming'));
    } else {
      res.json(find('upcoming'));
    }
  } else {
      res.json(find(req.query['type']));
  }
};

// setup express app ...

app.get('/events.json', handler);
// Using Groove.js
var all            = function(req, res) { res.json(find()); },
    eventsByType   = function(req, res) { res.json(find(req.query['type'])); },
    upcomingByCity = function(req, res) { res.json(findByCity(req.query['cityId'], 'upcoming')); };

// setup connect app ...
app.use(groove.route({
  'GET /events.json?type=upcoming&cityId=:cityId': upcomingByCity,
  'GET /events.json?type=:type': eventsByType
  'GET /events.json' : all,
}));

Flexibility

Because the input to the router is a simple object mapping URL patterns to functions, Groove.js doesn't impose any rules on how developers should organize their code.

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago