Routing

Routes are defined with an HTTP verb, path, and handler.

String Handlers

String handlers map to controller methods:

web.get('/', 'AppController@index');
web.get('/users/:id', 'UserController@show');

Functional Handlers

You can also use inline functions:

web.get('/health', () => new Response('OK', { status: 200 }));

Grouped routes

web.group('/users', (users) => {
    users.get('/', 'UsersController@index');
    users.get('/:id', 'UsersControllers@show');
})

Path Parameters

Named parameters are available through request params:

const id = req.params('id');
  • Keep route declarations in src/config/routes/web.ts.
  • Group routes by domain when the app grows.
  • Keep handlers thin and delegate to services.