Zum Inhalt springen

DAY 2 – Trie-Based Router Like Fastify

🌲Fastify (alternative of express) uses a Trie for route matching — today, I built my own.

✅ Each URL segment is a node in the tree

✅ Lookup is O(k) for k segments

✅ Supports /user/:id and wildcards

✅ Cleaner and faster than if-else chains

I never thought a data structure would make routing this efficient.

Frameworks do this behind the scenes — I wanted to understand the “why”.

Tomorrow I’ll move to a body parser that works in chunks.

This is a Github Gist u can see the implementation here. It’s a small portion of the code

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert