Iskra API Reference
    Preparing search index...

    Class Router

    Routes in groups, with the middleware each group shares:

    const api = new Router();
    const v1 = api.group('/api/v1', requestLog);
    v1.use(auth);
    v1.group('/users', requireScopes('users:read')).get('/:id', getUser);
    v1.unmatched({ then: 'auto' }); // auth runs first: a guest gets 401, not 404
    new WebPlugin({ router: api });

    The routes are registered on Hono by priority, not in the order they were added: static segments before parameters before wildcards (/users/me before /users/:id), and a route for a named method before one for every method. Two routes with the same method and path shape are an error.

    Hierarchy (View Summary)

    Index
    prefix: string

    The group's path prefix, /api/v1.

    registry: Registry
    • A route for every method (a named method's route on the same path comes first).

      Parameters

      Returns this

    • Registers the routes on app (a new Hono app by default), then the unmatched handlers, the most specific prefix first. WebPlugin does it on the Kernel's app; paths are the full ones, so compile onto the app that serves them rather than a sub-app mounted under a prefix.

      Parameters

      • app: Hono = ...

      Returns Hono

    • Parameters

      Returns this

    • Parameters

      Returns this

    • A route for method (or several): the group's middleware, then handlers.

      Parameters

      • method: string | readonly string[]
      • path: string
      • ...handlers: RouteHandler[]

      Returns this

    • Parameters

      Returns this

    • Parameters

      Returns this

    post

    • post(path: string, ...handlers: RouteHandler[]): this

      Parameters

      Returns this

    • Parameters

      Returns this

    • What happens to a request under this group's prefix that no route takes (an unknown path, a method with no route, a made-up method): it runs use (by default the group's middleware), then answers 404, or 405 with then: 'auto', by the response contract. Called again for the same prefix, the last call wins.

      Parameters

      Returns this

    • Adds middleware to the routes (and subgroups) added after this call.

      Parameters

      Returns this