Kito Framework - v1.0.0-alpha.8
    Preparing search index...

    Class KitoRouter<TExtensions>

    Router class for Kito. Provides HTTP routing and middleware support with the ability to mount sub-routers.

    const router = new KitoRouter();

    router.get('/', ({ res }) => {
    res.send('Hello from router!');
    });

    export default router;

    Type Parameters

    • TExtensions = {}

      Type of custom extensions added to the context

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Methods

    • Mounts a sub-router at the specified path.

      Parameters

      Returns this

      The router instance for chaining

      const apiRouter = router();
      apiRouter.get('/users', ({ res }) => res.json({ users: [] }));

      const app = server();
      app.mount('/api', apiRouter);

    post

    • Creates a route builder for chaining multiple HTTP methods on the same path.

      Parameters

      Returns RouteChain<TExtensions>

      Route chain builder

      router.route('/api/users')
      .get(({ res }) => res.json(users))
      .post(({ res }) => res.json({ created: true }))
      .end();
      const auth = middleware((ctx, next) => {
      // authentication logic
      next();
      });

      router.route('/admin', [auth])
      .get(({ res }) => res.send('Admin dashboard'))
      .post(({ res }) => res.send('Admin create'));