002 / experiment
route-table
Path patterns compiled once, matched in order, with overlaps left visible.
What
A table of method, pattern, and handler. Patterns like /notes/:slug become regular expressions when they are registered. A request walks the table from the top.
Why
I wanted to see first-match routing without a library explaining it to me. Overlapping patterns are the interesting case, and they are easier to see in a list than in a tree.
Architecture
Registration compiles the pattern and stores the names of the parameters. Matching tests the pathname only. The query string is parsed beside it, not inside the pattern. A hit returns the handler and a params object. A miss is just a miss.
Discoveries
The order of registration is the specification. A pattern registered later does not get a chance if an earlier one already matched. That feels crude until you notice that a lot of framework surprise is this rule, wearing a nicer API.