Routing to the endpoint
Routing is the phase where Fastify receives an HTTP request, and it must decide which handler function should fulfill that request. That’s it! It seems simple, but even this phase is optimized to be performant and to speed up your server.
Fastify uses an external module to implement the router logic called find-my-way (https://github.com/delvedor/find-my-way). All its features are exposed through the Fastify interface so that Fastify will benefit from every upgrade to this module. The strength of this router is the algorithm implemented to find the correct handler to execute.
The router under the hood
You might find it interesting that find-my-way implements the Radix-tree data structure, starting from the route’s URLs. The router traverses the tree to find the matched string URL whenever the server receives an HTTP request. Every route, tracked into the tree, carries all the information about the Fastify instance it belongs to.
During...