CORE CONCEPTS
Route Groups
router.group() scopes a URL prefix and a shared middleware stack to every route registered inside its callback. Groups can be nested.
Basic Usage
router.group('/api/v1', (api) => { api.get('/users', listUsers); // → GET /api/v1/users api.post('/users', createUser); // → POST /api/v1/users });
Shared Middleware
Pass an options object with middlewares to apply middleware to every route in the group:
router.group('/api/v1', { middlewares: [authMiddleware] }, (api) => { api.get('/users', listUsers); // authMiddleware runs first api.get('/orders', listOrders); // authMiddleware runs first }); // Routes outside the group are unaffected router.get('/health', healthCheck); // no authMiddleware
Nesting Groups
Groups combine their prefixes and middleware stacks as you nest them:
router.group('/api', { middlewares: [cors()] }, (api) => { api.group('/v1', { middlewares: [authMiddleware] }, (v1) => { v1.get('/users', listUsers); // → GET /api/v1/users, runs cors() then authMiddleware }); });
On Futon Directly
app.group() is a thin delegate to the same method on Futon's internal router, so you can skip creating a standalone Router entirely:
app.group('/api/v1', { middlewares: [authMiddleware] }, (api) => { api.get('/users', listUsers); });
Groups only affect registration
A group's prefix and middleware only apply to routes registered inside its callback. Once the callback returns, the router's middleware stack is restored to what it was before the group — sibling routes registered after the group are unaffected.
Route Patterns
Context Object
