HTTP Fundamentals

Routing

Register HTTP endpoints, parameters, named routes, groups, resources, and fallbacks.

Beta · v0.2.0Lanjit APIs may change before the stable release. Review the release notes and upgrade guide before updating.

Web routes live in routes/web.js; API routes automatically receive the /api prefix. Lanjit supports standard HTTP methods, {name} and :name parameters, named URL generation, middleware chains, route groups, resource controllers, and fallback handlers.

Examples

export default function routes(Route) {
  Route.get('/posts', listPosts);
  Route.post('/posts', createPost);
  Route.put('/posts/{id}', replacePost);
  Route.patch('/posts/{id}', updatePost);
  Route.delete('/posts/{id}', deletePost);
  Route.options('/posts', optionsHandler);
}
Route.get('/users/{user}', (request) => ({
  id: request.params.user,
}));
Route.get('/users/{user}', showUser).name('users.show');

const url = Route.url('users.show', { user: 42 });
// /users/42
Route.post('/profile', updateProfile)
  .middleware('session', 'csrf', 'auth', 'throttle:20,1');
Route.group({ prefix: '/admin', middleware: ['session', 'auth'] }, () => {
  Route.get('/dashboard', dashboard);
  Route.get('/users', users);
});
Route.resource('posts', PostController);
Route.fallback((request, response) => {
  return response.view('errors.404', {}, 404);
});
Edit this page on GitHub

Type to search all documentation.