Re:Show HN: A file tree based API Router
by rajnathani on Tuesday July 07, 2020 @10:21AM
(#23759551)
I created something I believe is exactly like this a while ago, one called xrest [0] which resolves the API endpoint routes from the file tree structure at runtime, and another called restree [1] which generates the routes before runtime by generating code.
Re:Show HN: A file tree based API Router
by MH15 on Tuesday July 07, 2020 @09:37AM
(#23759089)
This is very interesting, similar to serverless functions on Vercel or many other services. Will be interested to give it a try. Can you explain why there needs to be a compilation step?
Re:Show HN: A file tree based API Router
by aliezsid on Tuesday July 07, 2020 @09:44AM
(#23759166)
I create a tree similar to the file structure that is used by the actual router when it handles requests to figure out which handler to pass the `req` and `res` objects.
This is in the stable(`master`) branch.
The `canary` branch implements the same thing but instead of a object tree , it creates a flat object and uses regex's to find the registered handler which is faster but creates an overlap which I'm trying to fix.
In simple senses, it there's to make sure that the router only passes down the req,res to the valid handler and doesn't do any other processing other than maybe, query parsing and param parsing
[0] https://github.com/rajnathani/xrest
[1] https://github.com/rajnathani/restree
The `canary` branch implements the same thing but instead of a object tree , it creates a flat object and uses regex's to find the registered handler which is faster but creates an overlap which I'm trying to fix.
In simple senses, it there's to make sure that the router only passes down the req,res to the valid handler and doesn't do any other processing other than maybe, query parsing and param parsing