kartikk221 / hyper-express

High performance Node.js webserver with a simple-to-use API powered by uWebsockets.js under the hood.
MIT License
1.67k stars 87 forks source link

Path parameter regexp #278

Open Viper-Bit opened 2 months ago

Viper-Bit commented 2 months ago

hi @kartikk221, how about adding regexp in path (just path parameters or whole path) ? path parameter:

/users/:id(\\d+)/:tab(home|photos|bio)

whole path example:

/(user|u)/:id(\\d+)

we can use https://github.com/pillarjs/path-to-regexp to convert path to regexp or checking for ( ) in parse_path_parameters after each recognized path parameter

kartikk221 commented 2 months ago
Viper-Bit commented 2 months ago

@kartikk221

Does Express.js support a similar format?

yes express.js exactly using path-to-regexp package https://github.com/expressjs/express/blob/6d084715ba6ca5301e9ac1efe4309e555973b364/lib/router/layer.js#L16-L50 and also in express.js doc https://expressjs.com/en/4x/api.html#router.METHOD

Is there a simpler function or methodlogy to parse and apply the regex from a path without having to depend on another library?

maybe using find-my-way, fastify using find-my-way for parsing routes. based on router-benchmark find-my-way is so much faster

kartikk221 commented 1 month ago

I see, I will look into integrating this using native RegExp If possible for the best performance.

MinhazurSarker commented 5 days ago

Sounds like a bad idea