Skip to content

[core] Move routing into core and merge with mount() #4

Description

@justinfagnani

To enable the fastest routing we should avoid linear scans over both route patterns (in the Router) and middleware (in mount()). Instead we should have a trie-like structure for fast-matching requests against a collection of patterns and use in the Router.

Once we have a fast-at-scale Router, mount() becomes an anti-pattern, and because routing and mounting is such an important and primary task of a web server framework, routing should just move into core.

The future core API would merge the current App and Router classes.

Instead of a separate Router:

import {App, Router} from 'zipadee';

const app = new App();
const router = new Router();
router.get('/greet/:name', async (req, res, next, params) => {
  // ...
});
app.use(router.routes());

app.listen();

we'd have routing methods on App:

import {App} from 'zipadee';

const app = new App();
app.get('/greet/:name', async (req, res, next, params) => {
  // ...
});

app.listen();

Router would stick around to enable nested routers. App would implement the Router interface.

We will need an implementation of something like URLPatternList to match against a collection of URLPatterns. See whatwg/urlpattern#30

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions